If you are looking for TeX support, please use the VietTUG Google Group
Bash: some useful "set"
» Votes: 2/2
When using Bash, you can change the default behavior of the script/shell by
set command. Example
set -e: The script/shell will exit immediately if a simple command exits with a non-zero status, unless the command that fails is part of an until or while loop, part of an if statement, part of a
||list, or if the command's return status is being inverted using
set -C: Prevent output redirection using
from overwriting existing files. You need to use, for e.g,
tee -a, if you really want to overwrite some file.
set -u: Treat unset variables as an error when performing parameter expansion. An error message will be written to the standard error, and a non-interactive shell will exit.
set -x: Print a trace of simple commands and their arguments after they are expanded and before they are executed. This is very useful when debugging your script, though it is not really helpful in many cases.
set -u is very useful and it's highly recommended when your script/shell is running as
root. For example, if you invoke
rm -rfv /$_MY_DIR/etc/ and if the variable
$_MY_DIR isn't defined (unset), your script is simply executed as
rm -rfv /etc/ -- this is dangerous as that means that you delete all configuration on your server. Please note that, an unset variable isn't an empty variable. (A defined variable is DEFINED but it may as an EMPTY VALUE.)