19 ms·
A lot of the time you don't even have the luxury of assuming "bash" is present, you've got only "sh". Since all valid "sh" syntax is valid "bash", you've got t
by gavinray 5y ago
A lot of the time you don't even have the luxury of assuming "bash" is present, you've got only "sh".
Since all valid "sh" syntax is valid "bash", you've got to restrict yourself to only sh-valid code in the event the host doesn't have bash.
I have gotten used to doing this -- these scripts usually wind up being run in Docker containers that don't have "bash" installed for the sake of minimalism.
IE, you can't use [[ $predicate ]], but instead [ $predicate ], etc. Lot of subtle differences.
- Spivak 5y agoNot all sh syntax is valid bash — in bash [[ is reserved but not in sh. And if you want syntax that is valid but doesn’t do the same thing in sh vs bash there’s plenty of examples.
- kevin_thibedeau 5y agoYou can't ever assume that /bin/sh is a POSIX shell so then you get limited to just an early Bourne subset.