Gotchas in Shell Scripting

Shell scripting can be a little frustrating at times, I'm sharing some my gotchas to hopefully serve me as a reminder and help to help anyone else who may have gotten themselves stuck.

bash isn't sh

If you're writing a shell script always be explicit about the shell you wish to call. The first line of the shell script tells the system which shell you want to work with. Starting your script with #!/bin/sh will call the default shell for that system, which in Ubuntu Linux is no longer Bash but Dash, while a little faster, Dash is far less robust. Don't waste half a day trying do figure out why redirection isn't working, be explicit about the shell you want to use. If your writing for Bash, call it #!/bin/bash.


LinkedInGitHubTwitter