Why does zsh print cmdand for every && at the beginning of the line?
For instance when I paste the following lines into a Z shell
echo "foo" && echo "bar" && \ echo "buz" && \ echo "jam" ... zsh would display me the following
echo "foo" && echo "bar" && \ cmdand cmdand> echo "buz" && \ cmdand cmdand cmdand> echo "jam" So zsh prepends a cmdand for every && it encountered up to that line. I just noticed that similar holds for || and cmdor.
Why would this be useful at all? Doesn't it just clutter the console? Can this behaviour be controlled?
I observed this behaviour on Mac OS and Ubuntu for zsh versions >5.x.
1 Answer
It is controlled by the value of the environment variable PS2, whose default value '%_> ' gives this behaviour. Its purpose is to show where you are in a multi-line command (and not just lines ending in back-slash), eg if you type a conditional command over several lines you will get:-
$ if [ "$var" ] if> then then> echo var: $var then> else else> echo var: not set else> fi var: not set $ The shell does not distinguish between typed and pasted lines.
Set PS2='> ' for a simple > on each continuation line.
For more information, see the manual man zshall and search for PS2.