************** quote ***************************** #!/bin/tcsh set w = hi # * is interpreted echo * # * is NOT interpreted # command substitution and variable expansion is still done echo "*" echo "$w" echo "`date`" # command substitution and variable expansion is NOT done echo '*' echo '$w' echo '`date`' ************** quote output ***************************** branch cmd_args cond_cmd expression list loops mydir quote read_stdin * hi Wed Jul 30 01:58:17 MST 2003 * $w `date` *************** expression ***************************** #!/bin/tcsh # command substitution # wordlist set files = `ls` echo $files set n = $#files echo "n = $n" echo # numeric arithmetic @ a = 2 @ b = 5 @ c = $a + $b echo "c = $c" @ c = $a - $b echo "c = $c" @ c = $a * $b echo "c = $c" @ c = $a / $b echo "c = $c" @ c = $a % $b echo "c = $c" @ c += 20 echo "c = $c" @ c -- echo "c = $c" echo # wordlist index set w = (aaa bbb ccc ddd) echo "w = $w" @ w[1] = 111 @ w[3] = 333 echo "w = $w" echo # bitwise ops @ a = 8 echo "a = $a" @ b = ($a >> 2) echo "b = $b" @ b = ($a << 2) echo "b = $b" @ b = ~(127) echo "b = $b" @ b = ($a | 2) echo "b = $b" @ b = ($a & 2) echo "b = $b" @ b = ($a ^ 2) echo "b = $b" echo # logic ops @ a = 2 @ b = 5 @ c = ($a == 2) echo "c = $c" @ c = ($a > 1) echo "c = $c" @ c = !($a > 1) echo "c = $c" @ c = ($a > 1 && 2 < 10) echo "c = $c" @ c = ($a > 1 || $b < $a) echo "c = $c" ************* expression output ***************************** branch cmd_args cond_cmd expression list loops mydir/ quote read_stdin n = 9 c = 7 c = -3 c = 10 c = 0 c = 2 c = 22 c = 21 w = aaa bbb ccc ddd w = 111 bbb 333 ddd a = 8 b = 2 b = 32 b = -128 b = 10 b = 0 b = 10 c = 1 c = 1 c = 0 c = 1 c = 1 ************** loops ***************************** #!/bin/tcsh @ i = 0 while ($i < 10) echo "i = $i" @ i ++ end echo ---------------------------- set w = (aaa bbb ccc ddd) while ($#w > 0) echo $w[1] shift w end echo ---------------------------- set w = (111a 222b 333c 444d) foreach word ($w) echo $word end echo ---------------------------- foreach word (Winter Spring Summer Fall) echo $word end echo ---------------------------- foreach file (*) echo "file: $file" end echo ---------------------------- foreach file ($path) echo "path: $file" end ************* loops output ***************************** i = 0 i = 1 i = 2 i = 3 i = 4 i = 5 i = 6 i = 7 i = 8 i = 9 ---------------------------- aaa bbb ccc ddd ---------------------------- 111a 222b 333c 444d ---------------------------- Winter Spring Summer Fall ---------------------------- file: branch file: cmd_args file: cond_cmd file: expression file: list file: loops file: mydir file: quote file: read_stdin ---------------------------- path: /home/yao/local/bin path: /home/yao/timecenter/local/bin path: /home/yao/timecenter/mysql/MY_Home/bin path: /usr/local/bin path: /bin path: /sbin path: /usr/sbin path: /usr/ccs/bin path: /opt/SUNWspro/bin path: /usr/ucb path: /etc path: /usr/X11/bin path: /usr/openwin/bin path: /usr/local/bin path: /opt/unsupported/bin path: . path: /opt/oracle/OraHome1/bin *************** cmd_args ***************************** #!/bin/tcsh echo '$#argv =' "$#argv" echo '$argv =' "$argv" echo '$argv[*] =' "$argv[*]" echo '$* =' "$*" echo '$argv[$#argv] =' "$argv[$#argv]" foreach arg ($argv) echo $arg end *************** "cmd_args aa bb cc" output ************* $#argv = 3 $argv = aa bb cc $argv[*] = aa bb cc $* = aa bb cc $argv[$#argv] = cc aa bb cc *************** branch ***************************** #!/bin/tcsh @ i = 0 while ($i < 10) if ($i % 3 == 0) then echo "i = $i" endif @ i ++ end echo -------------------------- foreach file (*) if (-r $file) then echo "$file is readable" else echo "$file is not readable" endif if (! -d $file) then echo "$file is not directory" else echo "$file is directory" endif end echo -------------------------- set w = (aaaa bbbb book computer cs352) foreach word ($w) switch ($word) case aa*: echo "$word Match aa*" breaksw case *oo*: echo "$word Match *oo*" breaksw case 352: echo "$word Match 352" breaksw default: echo "$word Match default" endsw end echo -------------------------- @ i = 0 while (1) @ i ++ if ($i % 3 != 0) continue; echo "i = $i" if ($i > 10) break; end echo -------------------------- if (hello.c =~ *.c) echo "hello.c is a C file" if (hello.c !~ *.cc) echo "hello.c is NOT C++ file" ************ branch output ***************************** i = 0 i = 3 i = 6 i = 9 -------------------------- branch is readable branch is not directory cmd_args is readable cmd_args is not directory cond_cmd is readable cond_cmd is not directory expression is readable expression is not directory list is readable list is not directory loops is readable loops is not directory mydir is readable mydir is directory quote is readable quote is not directory read_stdin is readable read_stdin is not directory -------------------------- aaaa Match aa* bbbb Match default book Match *oo* computer Match default cs352 Match default -------------------------- i = 3 i = 6 i = 9 i = 12 -------------------------- hello.c is a C file hello.c is NOT C++ file *********** read_stdin ***************************** #!/bin/tcsh echo "Please enter a line and I will break it into words" set line = $< echo "The line is $line" foreach w ($line) echo "$w" end ********** read_stdin output ***************************** Please enter a line and I will break it into words hello world The line is hello hello