100 Useful Command-Line Utilities
by Oliver; 201448. set, unset
Use set to set various properties of your shell, somewhat analogous to a Preferences section in a GUI.E.g., use vi style key bindings in the terminal:
$ set -o viUse emacs style key bindings in the terminal:
$ set -o emacsYou can use set with the -x flag to debug:
set -x # activate debugging from here . . . set +x # de-activate debugging from hereThis causes all commands to be echoed to std:err before they are run. For example, consider the following script:
#!/bin/bash set -eux # the other flags are: # -e Exit immediately if a simple command exits with a non-zero status # -u Treat unset variables as an error when performing parameter expansion echo hello sleep 5 echo joeThis will echo every command before running it. The output is:
+ echo hello hello + sleep 5 + echo joe joeChanging gears, you can use unset to clear variables, as in:
$ TEST=asdf $ echo $TEST asdf $ unset TEST $ echo $TEST