My shell of choice and circumstance for most of my Linux life was Bash. Â So, naturally, in my head, shell pretty much equals Bash, and I rarely think or get into situations when this is not true. Â Recently, I was surprised by a script failure, which left me scratching my head. Â The command that failed in the script was pushd.
pushd and popd, it turns out, are built into Bash, but they are not standard POSIX commands, so not all the shells have them. Â My script wasn’t setting the shell explicitly, and end up executing with Dash, which I haven’t even heard of until this day. Â The homepage of Dash says the following:
DASH is not Bash compatible, it’s the other way around.
Mkay… So, I’ve done two things:
- Set /bin/bash explicitly as my shell in the script.
- Switch to “cd folder && do something && cd –“, instead of pushd/popd combination, where possible.
I knew about “cd –” before, but it was interesting to learn if there are any particular differences (hint: there are) between the this approach and the pushd/popd one that I was using until now. Â This StackOverflow thread (ok, ok, Unix StackExchange) was very helpful.