实用 Unix/Linux 系统管理脚本解析
1. 环境验证脚本(validator)
在 Unix/Linux 系统中,环境变量的正确设置至关重要。环境验证脚本validator可以帮助用户快速检查自身环境是否存在问题。
if [ ! -d ${HOME:?"You need to have your HOME set to your home directory"} ] then echo "** HOME set to $HOME, but it's not a directory." errors=$(( $errors + 1 )) fi # Our first interesting test: Are all the paths in PATH valid? oldIFS=$IFS; IFS=":" # IFS is the field separator. We'll change to ':'. for directory in $PATH do if [ ! -d $directory ] ; then echo "** PATH contains invalid directory $directory." errors=$(( $errors + 1 )) fi done IFS=$oldIFS # Restore value for rest of script. # The following variables should each be a fully qualified path, # but they m