When you run
this executes an interactive shell as root (
sudo su), then when that shell terminates the csh script is executed. Similarly, the
temp.csh script first executes an interactive tcsh, then changes its current directory just before exiting.
To execute a csh script as root, run
To execute an interactive instance of tcsh as root, which I think is what you're trying to do, run
To execute that tcsh instance in a particular directory, change the directory before running sudo.
cd /path/to/directory && sudo tcsh
Note that in many installations,
sudo wipes most of the environment, so don't expect environment variables set in the wrapper script to be available in the tcsh session.
You can't pass a script to execute at the beginning of a tcsh session, other than the profile files (
~/.login for login shells,
~/.cshrc for all tcsh instances). If you want to run some initial commands, put them in
~/.cshrc (possibly inside a conditional construct). Alternatively, for commands that only execute programs, set environment variables, change the current directory and the like, you can use a wrapper script like the one below; this does not work to change the shell environment (for example, to set csh variables with
# commands go here
setenv foo bar