bash - GNU Bourne-Again SHell
bash [options] [command_string | file]
Options you will use
-c string- Read and execute commands from string, then exit.
-n- Read commands but do not execute them. Syntax check only.
-x- Print each command and its expanded arguments to stderr before running it (xtrace).
-e- Exit immediately if a command exits non-zero. See the gotchas in NOTES.
-u- Treat unset variables as an error when substituting.
-o pipefail- A pipeline returns the status of the rightmost command that failed.
-s- Read commands from standard input.
--noprofile- Do not read /etc/profile or ~/.bash_profile (login start files).
--norc- Do not read ~/.bashrc.
Examples
$ bash -n script.shsyntax-check a script without running it
$ bash -x script.shtrace every command as it runs
$ bash -c 'echo $BASH_VERSION'run one command string
Gotchas
- set -e does NOT fire for a command in a condition (if/while/&&/||), for any command in a pipeline except the last (use pipefail), or for
local x=$(cmd)-localis the command whose status is seen. - set -u catches unset variables, but "${arr[@]}" on an empty array is fine in bash 4.4+.
Taught in
Try bash in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.