Wiki
Table Of Contents
-
Bash
- Script Directory
- Check
- Bold Echo
- Die
getopts Shift
Bash
Script Directory
Determine the directory in which a bash script is located:
prog_dir=$(dirname $(realpath "$0"))
Check
Check the previous command succeeded and print an
error message if it failed:
check() {
if [[ "$?" != "0" ]]; then
die "$@"
fi
}
Bold Echo
Print bold text:
bold() {
echo "$(tput bold)$@$(tput sgr0)"
}
Die
Print error to stderr and exit:
die() {
echo "Error: $@" >&2
exit 1
}
getopts Shift
Shift after getopts:
shift $((OPTIND-1))