If I want to use the non-POSIX [[ and (( test forms in my scripts, and I declare the shell I want use with
#!/bin/bash
at the beginning of my scripts, will calling the Bash shell directly prevent any problems that might arise from using those forms? Or will some other shell automatically be used if the shell referenced in the hash-bang isn't found?
Both Linux and OS X will refuse to execute the script if the executable specified on the shebang line is not found (haven't tried others).
You'll see something like /bin/bash: bad interpreter: No such file or directory and the exit code will be 127.
However, a more portable way of referencing the desired shell is to write the shebang line as follows (e.g., for bash):
#!/usr/bin/env bash
That way, the shell executable will be found as long as it is in the $PATH.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With