Whenever the output of a command is piped to another in bash, which command will the exit value (the $?
variable) be returned from? The command that the output was piped from, or the command that the output was piped to?
Say, for example, in the command:
git diff | vim -
Would the $?
variable come from the git diff
command, or the vim -
command?
Answer
The last command in the pipe.
$ false | echo -n
$ echo $?
0
$ true | echo -n
$ echo $?
0
$ true | echo -n | false
$ echo $?
1
No comments:
Post a Comment