mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-11 20:48:49 +00:00
Document && and ||
This commit is contained in:
parent
9bb2d1e79f
commit
0938c9f427
3 changed files with 15 additions and 8 deletions
|
@ -281,7 +281,7 @@ The fish user community extends fish in unique and useful ways via scripts that
|
|||
- <a href="https://github.com/oh-my-fish/oh-my-fish">Oh My Fish</a>
|
||||
- <a href="https://github.com/justinmayer/tacklebox">Tacklebox</a>
|
||||
|
||||
This is not an exhaustive list and the fish project has no opinion regarding the merits of the repositories listed above or the scripts found therein. We mention these only because you may find within them a solution to a need you have such as supporting the `&&` and `||` operators or improved integration with other tools that you use.
|
||||
This is not an exhaustive list and the fish project has no opinion regarding the merits of the repositories listed above or the scripts found therein.
|
||||
|
||||
\htmlonly[block]
|
||||
</div>
|
||||
|
|
|
@ -420,17 +420,23 @@ echo chips
|
|||
|
||||
\section tut_combiners Combiners (And, Or, Not)
|
||||
|
||||
Unlike other shells, `fish` does not have special syntax like && or || to combine commands. Instead it has commands `and`, `or`, and `not`.
|
||||
fish supports the familiar `&&` and `||` to combine commands, and `!` to negate them:
|
||||
|
||||
\fish{cli-dark}
|
||||
>_ cp file1.txt file1_bak.txt; and echo "Backup successful"; or echo "Backup failed"
|
||||
>_ ./configure && make && sudo make install
|
||||
\endfish
|
||||
|
||||
fish also supports `and`, `or`, and `not`. The first two are job modifiers and have lower precedence. Example usage:
|
||||
|
||||
\fish{cli-dark}
|
||||
>_ cp file1.txt file1_bak.txt && cp file2.txt file2_bak.txt ; and echo "Backup successful"; or echo "Backup failed"
|
||||
<outp>Backup failed</outp>
|
||||
\endfish
|
||||
|
||||
As mentioned in <a href="#tut_semicolon">the section on the semicolon</a>, this can also be written in multiple lines, like so:
|
||||
|
||||
\fish
|
||||
cp file1.txt file1_bak.txt
|
||||
cp file1.txt file1_bak.txt && cp file2.txt file2_bak.txt
|
||||
and echo "Backup successful"
|
||||
or echo "Backup failed"
|
||||
\endfish
|
||||
|
|
|
@ -584,10 +584,11 @@ x
|
|||
# A special case. Tidy up after performing command substitution.
|
||||
# Redirectors
|
||||
s/\([^{|] *\)|/\1@redr{|}/g
|
||||
s/\&@EOL$/@redr{@amp}@EOL/g
|
||||
s/@amp@EOL$/@redr{@amp}@EOL/g
|
||||
s/\([<>]\)@amp\([0-9]\)/@redr{\1@amp\2}/g
|
||||
s/\([^{&] *\)&[^@a-z]/\1@redr{\&}/g
|
||||
#s/\&@EOL$/@redr{@amp}@EOL/g
|
||||
#s/@amp@EOL$/@redr{@amp}@EOL/g
|
||||
#s/\([<>]\)@amp\([0-9]\)/@redr{\1@amp\2}/g
|
||||
s/@amp&/@optr{@amp@amp}/g
|
||||
#s/\([^{&] *\)&[^@a-z]/\1@redr{\&}/g
|
||||
s/\([^{<>^] *\)\([0-9]* *[<>^][<>^]*[^@][a-zA-Z0-9./_-]*\)/\1@redr{\2}/g
|
||||
s/\\}/}\\/g
|
||||
#.
|
||||
|
|
Loading…
Reference in a new issue