-
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
Description:
- The command
ls
lists the contents of the current directory. - The output of
ls
is piped to thewc
command, which counts the number of lines, words, and characters. - The output of
wc
is then piped to the non-existent commandasdf
. - Since
asdf
does not exist, the exit code ($?
) is 127, indicating a command error.
-
Command:
asdf | ls | wc
-
Result:
echo $?
is0
Description:
- The non-existent command
asdf
attempts to pass its output tols
. - The command
ls
lists the contents of the current directory. - The output of
ls
is then piped to thewc
command, which counts the number of lines, words, and characters. - Since the previous commands were successful, the exit code (
$?
) is 0, indicating successful execution.
-
Command:
ls | asdf | wc
-
Result:
echo $?
is0
Description:
- The command
ls
lists the contents of the current directory. - The output of
ls
is piped to the non-existent commandasdf
. - Since
asdf
does not exist, the output ofls
is directly piped to thewc
command. - Since the previous commands were successful, the exit code (
$?
) is 0, indicating successful execution.