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:
Fabian Homborg 2017-05-19 18:54:24 +02:00 committed by David Adam
parent 3cca94b268
commit fdea1abf70

View file

@ -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?