CSHnutshell
CSHnutshell
Variables:
User Defined:
Use set or @ to define variables Ex. set myVar = asdf echo $myVar outputs asdf Use setenv for environment variables unset or unsetenv to clear variables setenv myVar Asdf arrays set myVar[1] = asdf Command Substitution set myVar = `date` foreach mThing ( arg list ) echo $mThing end
User Input
parameters: while($#argv != 0) echo $1 shift end runtime input:
echo n enter your age set myVar = $<
Built In environment:
HOME PATH MAIL USER SHELL TERM The full pathname of your home directory. A List of directories to search for commands. The full pathname of your mailbox. Your user id. The full pathname of your login shell. The type of your terminal.
Gotchas
debug: csh x scriptName
Control Structures:
if ( expr ) then #do stuff else #do something else endif while ( expr ) #do something end switch ( expr ) case 1: echo 1 breaksw default: echo not 1 breaksw; endsw
Built In shell:
cwd history ignoreeof The current working directory The size of the history list Prevents the shell from terminating when pressing Control-D. Use the logout or exit command. Prevents existing files from being overridden by output redirection (>), and non-existent files from being appended by append (>>) The exit code status of the last command The shell primary prompt The number of commands
noclobber
outputs commands before execution make sure there are spaces in control structures if(1) != if (1) != if ( 1) != if ( 1 ) correct: if ( 1 ) grep "$myVar$" < file FAIL myVar = asdf grep "$myVar"'$' <file for file named asdf$ There has to be newlines after endif Escaping newlines is pretty much impossible. Dont even try it ! is a special character everywhere. Escape it. double quotes toggle the interpret/no interpret parser. So, echo $home == $home echo $home == contents of var home This is especially useful when using awk. you cant escape variables in double quotes either. cat $file | if ($a ) then FAIL you cant pipe to control structures arguments passed with spaces arent parsed correctly.