C Shell Scripting
From Rizzo_Lab
Contents
Header information
#!/bin/tcsh indicates that the script is writing in tcsh #PBS -l nodes=1:ppn=2 use 1 node and 2 processors per node #PBS -l walltime=01:00:00 run for a maximum time of 1 hour #PBS -N dock6 set the name of the job to 'dock6' #PBS -M user@sunysb.edu your e-mail address (optional) #PBS -j oe join the output and error files #PBS -o pbs.out set the output name to 'pbs.out'
General commands
set var = 'value' assign 'value' to the variable 'var' @ var = $var + 1 modify the assignment of 'var' (increment by 1) echo $var print the contents of the variable 'var'
If / else
set number = 5 if ($number < 9) then echo 'less than 9' else echo 'Greater than 9' endif
Expected output: less than 9
Foreach loop
foreach var (1AIK 2PK8 3O3X) mkdir $var echo 'Just made the new dir' $var end
Expected output: Just made the new dir 1AIK Just made the new dir 2PK8 Just made the new dir 3O3X
While loop
set count = 1 echo $count while ($count <= 10) echo Count = $count @ count ++ end
Expected output: 1 Count = 1 Count = 2 Count = 3 ... Count = 10
Other things to know
# Any text that comes after a '#' sign is ignored, other than the special cases shown above. This is a useful way to make comments in the scripts.