#!/bin/bash # validator--Checks to ensure that the PATH contains only valid directories, # then checks that all environment variables are valid. # Looks at SHELL, HOME, PATH, EDITOR, MAIL, and PAGER. setglobal errors = '0' source ../1/library.sh # which contains Script #1, the in_path() function proc validate { setglobal varname = $1 setglobal varvalue = $2 if test ! -z $varvalue { if test $(varvalue%${varvalue#?}) = "/" { if test ! -x $varvalue { echo "** $varname set to $varvalue, but I cannot find executable." sh-expr ' errors++ ' } } else { if in_path $varvalue $PATH { echo "** $varname set to $varvalue, but I cannot find it in PATH." setglobal errors = $shExpr(' $errors + 1 ') } } } } # BEGIN MAIN SCRIPT # ================= if test ! -x $(SHELL:?"Cannot proceed without SHELL being defined.") { echo "** SHELL set to $SHELL, but I cannot find that executable." setglobal errors = $shExpr(' $errors + 1 ') } if test ! -d $(HOME:?"You need to have your HOME set to your home directory") { echo "** HOME set to $HOME, but it's not a directory." setglobal errors = $shExpr(' $errors + 1 ') } # Our first interesting test: Are all the paths in PATH valid? setglobal oldIFS = $IFS; setglobal IFS = '":'" # IFS is the field separator. We'll change to ':' for directory in [$PATH] { if test ! -d $directory { echo "** PATH contains invalid directory $directory" setglobal errors = $shExpr(' $errors + 1 ') } } setglobal IFS = $oldIFS # restore value for rest of script # The following variables should each be a fully qualified path, # but they may be either undefined or a progname. Add additional # variables as necessary for your site and user community. validate "EDITOR" $EDITOR validate "MAILER" $MAILER validate "PAGER" $PAGER # And, finally, a different ending depending on whether errors > 0 if test $errors -gt 0 { echo "Errors encountered. Please notify sysadmin for help." } else { echo "Your environment checks out fine." } exit 0