-
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
lscommand lists the contents of the current directory. - The output of
lsis piped to thewccommand, counting lines, words, and characters. - The result is then piped to the non-existent command
asdf. - Since
asdfis 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
asdfattempts to pass its output tols. -
lsthen lists the contents of the current directory. - The output of
lsis piped to thewccommand, 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
lscommand lists the contents of the current directory. - The output of
lsis piped to the non-existent commandasdf. - As
asdfis missing, the output oflsis directly piped to thewccommand. - 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!