Source: levelup.gitconnected.com

9 Tips For Writing Safer Shell Scripts

Category: shell

Shell scripting is a powerful tool available on all platforms, even Windows, thanks to WSL. Many of them are considered safer than the shell defaults.

By default, a shell script is run entirely, regardless of any errors: By setting -e we can prevent the echo: There are certain exceptions to make it actually more usable: Never trip over unset variables ever again!

And thanks to shebangs we can use many different languages in scripts, given a suitable interpreter is available: Or we could always use a “compiles to single binary”-style language, like Golang or Rust.

hey are easy to use and integrate into our workflow, and shouldn’t be dismissed due to convenience, especially if others have to use our scripts.

Related Articles