I understand that when I call exit, it is an alias for logout. Sometimes, just for fun, when I need to remove myself from a session I will type exit && 1
. Now what happens after the exit
has been executed. Where does the 1
go? Typing 1 into bash yields (obviously) this: 1: command not found
. I'm not asking why 1 doesn't work. I'm asking where does the 1 go after calling exit? 1 is just an example, replace it with any other command.
But typing exit &&&&&&& 1
yields a syntax error. So the right hand must be evaluated.
Disclaimer : This is a question in which interests me. There is not particular reason for this question besides the fact that I am curious about what happens.
Best Answer
When you type
exit
, the shell will quit immediately,1
is not evaluated. If you check the source code for exit, you can see:The last thing
exit
does:return (exit_or_logout (list))
The syntax error in
exit &&&&&&& 1
due to parsing error, not the result of evaluating expression. Parsing occurs before any command run.