mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Update docs to reflect new if/while condtion chaining
Documents new behavior in #1428
Cherry picked from 30ea7cc3f8
This commit is contained in:
parent
768277a312
commit
ade6ebf522
4 changed files with 15 additions and 16 deletions
|
@ -7,11 +7,12 @@ COMMAND1; and COMMAND2
|
|||
|
||||
\subsection and-description Description
|
||||
|
||||
`and` is used to execute a command if the current exit status (as set by the last previous command) is 0.
|
||||
`and` is used to execute a command if the current exit status (as set by the previous command) is 0.
|
||||
|
||||
`and` does not change the current exit status.
|
||||
`and` statements may be used as part of the condition in an <a href="#if">`and`</a> or <a href="#while">`while`</a> block. See the documentation
|
||||
for <a href="#if">`if`</a> and <a href="#while">`while`</a> for examples.
|
||||
|
||||
The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.
|
||||
`and` does not change the current exit status. The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.
|
||||
|
||||
|
||||
\subsection and-example Example
|
||||
|
|
|
@ -12,7 +12,7 @@ end
|
|||
|
||||
`if` will execute the command `CONDITION`. If the condition's exit status is 0, the commands `COMMANDS_TRUE` will execute. If the exit status is not 0 and `else` is given, `COMMANDS_FALSE` will be executed.
|
||||
|
||||
In order to use the exit status of multiple commands as the condition of an if block, use <a href="#begin">`begin; ...; end`</a> and the short circuit commands <a href="commands.html#and">`and`</a> and <a href="commands.html#or">`or`</a>.
|
||||
You can use <a href="#and">`and`</a> or <a href="#and">`or`</a> in the condition. See the second example below.
|
||||
|
||||
The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.
|
||||
|
||||
|
@ -33,9 +33,8 @@ end
|
|||
|
||||
The following code will print "foo.txt exists and is readable" if foo.txt is a regular file and readable
|
||||
\fish
|
||||
if begin test -f foo.txt
|
||||
and test -r foo.txt
|
||||
end
|
||||
if test -f foo.txt
|
||||
and test -r foo.txt
|
||||
echo "foo.txt exists and is readable"
|
||||
end
|
||||
\endfish
|
||||
|
|
|
@ -7,12 +7,12 @@ COMMAND1; or COMMAND2
|
|||
|
||||
\subsection or-description Description
|
||||
|
||||
`or` is used to execute a command if the current exit status (as set by the last previous command) is not 0.
|
||||
`or` is used to execute a command if the current exit status (as set by the previous command) is not 0.
|
||||
|
||||
`or` does not change the current exit status.
|
||||
|
||||
The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.
|
||||
`or` statements may be used as part of the condition in an <a href="#if">`and`</a> or <a href="#while">`while`</a> block. See the documentation
|
||||
for <a href="#if">`if`</a> and <a href="#while">`while`</a> for examples.
|
||||
|
||||
`or` does not change the current exit status. The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.
|
||||
|
||||
\subsection or-example Example
|
||||
|
||||
|
|
|
@ -11,12 +11,11 @@ while CONDITION; COMMANDS...; end
|
|||
|
||||
If the exit status of `CONDITION` is non-zero on the first iteration, `COMMANDS` will not be executed at all.
|
||||
|
||||
Use <a href="#begin">`begin; ...; end`</a> for complex conditions; more complex control can be achieved with `while true` containing a <a href="#break">break</a>.
|
||||
|
||||
You can use <a href="#and">`and`</a> or <a href="#and">`or`</a> for complex conditions. Even more complex control can be achieved with `while true` containing a <a href="#break">break</a>.
|
||||
|
||||
\subsection while-example Example
|
||||
|
||||
\fish
|
||||
while test -f foo.txt; echo file exists; sleep 10; end
|
||||
# outputs 'file exists' at 10 second intervals as long as the file foo.txt exists.
|
||||
while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end
|
||||
# outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists.
|
||||
\endfish
|
Loading…
Reference in a new issue