nonroot: Undefined variable.

When running a C shell script on RHEL 3 AS, I receive the following output:

# ./script.csh
nonroot: Undefined variable.

/bin/csh is a symbolic link to /bin/tcsh.

# ls -l /bin/csh /bin/tcsh
lrwxrwxrwx    1 root     root            4 Dec 22  2004 /bin/csh -> tcsh
-rwxr-xr-x    1 root     root       314516 Oct  3  2004 /bin/tcsh

When executing the script, the prompt variable is not set, so ~/.tcshrc returns an error when executing echo $nonroot.

csh -V script.csh
...
if ( $?prompt ) then

echo $nonroot
nonroot: Undefined variable.

As a workaround, use the shell's -f flag, which prevents ~/.tcshrc from being sourced.

From TCSH(1):
       -f  The shell ignores ~/.tcshrc, and thus starts faster.

# csh -f scripts.csh

Back to brandonhutchinson.com.
Last modified: 2007/08/13