Read first line of a file into a variable

To put the first line of the file /etc/sympa/cookie into the variable $COOKIE use the read builtin:

~ read -r COOKIE < /etc/sympa/cookie

Verify environment variable

Check that environment variable API_USER is present and not empty:

: "${API_USER:?Please set API_USER environment variable}"


Default value for first command line parameter:


The substitution can be any shell syntax, even a command:

DATE=${1:-`date +"%Y-%B"`}

Check syntax of shell script

$ bash -n myscript



How To Use Bash History Commands and Expansions