mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
docs: Improve faq-exit-status
Add examples, a mention of `if command` and link to test/if.
See #2773.
(cherry picked from commit 64d33fac5d
)
This commit is contained in:
parent
3cca94b268
commit
fdea1abf70
1 changed files with 20 additions and 0 deletions
|
@ -86,6 +86,26 @@ end
|
|||
|
||||
Use the `$status` variable. This replaces the `$?` variable used in some other shells.
|
||||
|
||||
\fish{cli-dark}
|
||||
somecommand
|
||||
if test $status -eq 7
|
||||
echo "That's my lucky number!"
|
||||
end
|
||||
\endfish
|
||||
|
||||
If you are just interested in success or failure, you can run the command directly as the if-condition:
|
||||
|
||||
\fish{cli-dark}
|
||||
if somecommand
|
||||
echo "Command succeeded"
|
||||
else
|
||||
echo "Command failed"
|
||||
end
|
||||
\endfish
|
||||
|
||||
See the documentation for <a href="commands.html#test">`test`</a> and <a href="commands.html#if">`if`</a> for more information.
|
||||
|
||||
Use the <a href="commands.html#fish_update_completions">`fish_update_completions`</a> command.
|
||||
<hr>
|
||||
\section faq-single-env How do I set an environment variable for just one command?
|
||||
|
||||
|
|
Loading…
Reference in a new issue