Hacker News new | ask | show | jobs
by throw0101b 1043 days ago
> bash was written a decade prior to standardization, and has interesting issues because of this.

bash can do whatever it wants to do if it's called as "bash". But it should only do specific things when called as "sh". This is true of any shell:

> When interpreted with dash instead of bash, the same script will fail. This is because dash is much stricter than bash in following the sh standard. Since dash is designed as a minimal implementation of the sh standard, it has to be stricter. The double brackets [[ … ]] are a ‘bashism,’ or a feature only available in bash and other, later shells such as ksh and zsh.

> Even though zsh also interprets most of these bashisms, zsh in sh compatibility mode is also stricter than bash and will error.

* https://scriptingosx.com/2020/06/about-bash-zsh-sh-and-dash-...

* https://zsh.sourceforge.io/Doc/Release/Invocation.html#Compa...

POSIX.2: Shell and Utilities (IEEE Std 1003.2-1992) is a few decades old now: regardless of when bash development started, I would think that by the 2010s it would have managed to better compartmentalize compatibility and extensions.

1 comments

One interesting expression of the bash personality disorder is alias.

If you alias p=printf in a #!/bin/sh script, it will work; it will fail in a #/bin/bash script, unless POSIX mode is forced.