-
Notifications
You must be signed in to change notification settings - Fork 0
EXIT codes in bash
panndabea edited this page Jan 14, 2024
·
6 revisions
-
Command:
ls | wc | asdf
-
Result:
echo $?
is127
Details and Quick Tip
- The
ls
command lists the contents of the current directory. - The output of
ls
is piped to thewc
command, counting lines, words, and characters. - The result is then piped to the non-existent command
asdf
. - Since
asdf
is not found, the exit code ($?
) is 127, indicating a command error.
Quick Tip: Copy and paste the command into your terminal to see the outcome!
-
Command:
asdf | ls | wc
-
Result:
echo $?
is0
Details and Quick Tip
- The non-existent command
asdf
attempts to pass its output tols
. -
ls
then lists the contents of the current directory. - The output of
ls
is piped to thewc
command, counting lines, words, and characters. - As the previous commands were successful, the exit code (
$?
) is 0, indicating success.
Quick Tip: Copy and paste the command into your terminal to observe the result!
-
Command:
ls | asdf | wc
-
Result:
echo $?
is0
Details and Quick Tip
- The
ls
command lists the contents of the current directory. - The output of
ls
is piped to the non-existent commandasdf
. - As
asdf
is missing, the output ofls
is directly piped to thewc
command. - The exit code (
$?
) is 0, indicating successful execution of the previous commands.
Quick Tip: Copy and paste the command into your terminal for a hands-on experience!