4 ms·
[[ and ]] are not portable. [ and ] are portable and specified in POSIX. Like if you always use [[ and ]] you are going to be surprised when the default shell
by distcs 3y ago
[[ and ]] are not portable. [ and ] are portable and specified in POSIX.
Like if you always use [[ and ]] you are going to be surprised when the default shell used for running unattended scripts in Debian, Ubuntu refuses to run your script.
dash: 1: [[: not found
I know your parent commenter mentioned "#!/bin/bash" so your point is still valid. But I recommend that always use "#!/bin/sh" and always use [ and ] so that the scripts are portable.
I say this as a former package maintainer who has spent a great deal of time converting Bash scripts to POSIX sh scripts just so that I can package them as .deb.
- hakre 3y agoIMHO this is also a good remark in context of those container images that most of all have /bin/sh. Technically not all, but many distro based containers. so if someone plans to extend the script so that it injects it iself into the container or what not.
- rascul 3y agoI'll take the bash dependency. The features are well worth it.