Update last article based on user comments
This commit is contained in:
parent
4eea3090d6
commit
e1be67db1c
|
@ -158,12 +158,19 @@ it is empty, so you won't even need conditionals.
|
|||
Most other shells support similar operators. [fish][fish] uses `; and` and `;
|
||||
or`, but now [supports][fish-and-and] `&&` and `||` as well in modern versions.
|
||||
|
||||
`$_` (or `Alt+.`) is your last used argument (thanks [@Diti](https://lobste.rs/s/nao13f/elegant_bash_conditionals#c_brp038)). For example:
|
||||
`$_` (or `Alt+.`) is your last used argument (noted by [@Diti](https://lobste.rs/s/nao13f/elegant_bash_conditionals#c_brp038)).
|
||||
For example:
|
||||
|
||||
```bash
|
||||
test -f FILE && source $_ || echo "FILE does not exist" >&2
|
||||
test -f "FILE" && source "$_" || echo "$_ does not exist" >&2
|
||||
```
|
||||
|
||||
A function or script returns the exit code of the last expression. If your last
|
||||
expression is a command chain as described in this article, you might have an
|
||||
unexpected exit code. See
|
||||
[this](https://www.reddit.com/r/linux/comments/lw0ofg/elegant_bash_conditionals/gpf1lr0/)
|
||||
comments.
|
||||
|
||||
## Closing thoughts
|
||||
These command sequences with control operators are an elegant alternative for
|
||||
simple if-statements. I think they look much better and are more expressive
|
||||
|
|
Loading…
Reference in New Issue