Shell variables are set using the form set var = value. Space around the = is okay. Environment variables are set with setenv var and examined with printenv.
tcsh% echo $v v: Undefined variable. tcsh% set v = 12 tcsh% echo $v 12 tcsh% printenv v tcsh% tcsh tcsh% echo $v v: Undefined variable. tcsh% printenv v tcsh% exit exit tcsh% setenv v 14 tcsh% echo $v 12 tcsh% printenv v 14 tcsh% tcsh tcsh% echo $v 14 tcsh% printenv v 14 tcsh% exit exit
We can do everything with if statements. The general form is shown below in the shell program. Additional tests on files are given following.
#! /bin/csh -f # Set some local (shell) variables set var = 12 if ($var == 12) then echo The variable is twelve. else echo The variable is $var. endif
if (-op filename) then expr endif
op | Test |
---|---|
r | Readable? |
w | Writable? |
x | Executable? |
e | Exists? |
o | Is owner of? |
z | Is empty? |
f | Is plain file? |
d | Is directory? |
l | Is symbolic link? |
foreach var ( list ) statements end
For example, the script:
foreach n ( 1 2 3 4 ) echo $n end
produces
1 2 3 4