set -o errexit
# OR
set -e
-e
indicates that from that point forward, all errors will trigger an EXIT signal.
set -o nounset
# OR
set -u
# legacy
user=`echo `$USER`
# recommended
user=$(echo $USER)
readonly passwd_file=”/etc/passwd”
readonly group_file=”/etc/group”
All bash environment variables are named with uppercase letters, therefore use lowercase letters to name your custom variables to avoid variable name conflicts.
It's useful to include a -h
or --help
flag which prints usage information about the script
if [[ ${#@} -ne 0 ]] && [[ "${@#"--help"}" = "" ]]; then
printf -- '...help...\n';
exit 0;
fi;
Command is a bash built-in.
command -v binary-name
docker=$(command -v docker);
if [ "$docker" != "0" ]; then
print -e -- 'Docker is not installed';
exit 127;
127 - command not found
0 - success
1 - general errors such as "divide by zero" and other impermissible operations
echo -e '\u2718' # check mark
echo -e '\u2714' # cross mark
echo -e '\u2717' # heavy check mark
echo -e '\u2713' # heavy cross mark