While for the most part you may never run into an issue when writing (and using) shell scripts, there’s one little caveat that I’ve experienced as of late.
Instead of starting your scripts with this:
You will most likely better off in the long run specifying the exact shell you want to use. For example, if you want to use Bash:
The problem here is that /bin/sh is generally a symlink to a shell program (Bash, Dash, etc…). While this is handy, not every shell is going to have the same features. For example, in Bash, if you want to create an array variable, you’d do this:
VARNAME=(arrayval1 arrayval2 etc…)
However, on my VPS, /bin/sh is linked to /bin/dash, which doesn’t allow you to create arrays like that. If you want to to see where your /bin/sh is linked to, you can run the following command:
ls -liha /bin | grep “sh ->” | grep lrwxrwxrwx
There might be multiple entries. You could remove it then recreate the symlink, but if you’re going to write scripts for portability (like what I offer on this blog), you should specify the exact shell to be on the safe side.