Shell Symbol Meaning
Shell Symbol Meaning
A very useful feature of C shell is the alias mechanism, as shown in the example in which ls -l is assigned to mydir, checked and deassigned.
% alias mydir ls -l % mydir drwxr-xr-x 2 john users -rwxr-xr-x 1 john users -rwxr-xr-x 1 john users % alias mydir (ls -l) % unalias unalias: Too few arguments. % unalias mydir % alias 8192 Jul 1 15:33 badcom 342 Jul 13 11:50 exists.csh 336 Jul 13 12:05 exists.ksh
The alias buil-tin allows argument substitution, as shown in the example below.
% alias last % alias last2 echo \!:$ echo \!:2:t # print last echo argument # print tail (t) of second argument (2)
alias syntax \ !: define argument substitution n :t select argument by no. (1:$), where $ = last argument modifier ( h = head, r = remove extension, t = tail)
N.B. modifiers act on path (h, t) or filename extension (r) C shell acts on variables through the set, @ and setenv commands. @ interpreters variables as numbers. set and @ operate on local variables, setenv operates on global variables. C shell Variable Manipulation set set tape list all variables create empty variable tape
set tape = test create and fill variable tape with value test set tape = new modify variable tape set tape unset tape reset variable tape to void remove variable tape
C shell Variable Substitution $var ${var} $var[j] ${var[j]} select j-th word of variable replace variable contents
[j-i] selects a range, [-i] selects 1:i elements [i-] select i: last elements, * selects all elements $#var ${#var} $0 $n ${n} $ $?var $?{var} $?0 $$ $< modifiers substitute str1 if var set, otherwise 0 substitute 1 if current input known, otherwise 0 substitute decimal PID of parent shell substitute a line from stdin to read from keyboard :gh, :gt, :gr, :h, :t, :r, :q, :x equivalent to $argv[n] equivalent to $argv[*] no. of words in variable command name
No modifiers for: $?var, ${?var}, $?0, $?{0}, $$, $< C shell allows the definition and manipulation of arrays according to the syntax shown in the example below.
% set rgb = ( red green blue yello magenta cyan ) % echo $rgb red green blue yello magenta cyan % echo $rgb[4] yello % set rgb[4]=yellow % echo $rgb[4] yellow
Numeric values are defined by the @ operator that must be suffixed by a space to apply to variable. Numeric values are used with operators following the C programming language syntax rules as shown in the following example:
% n = 120 % echo $n 120 % echo $arr arr: Undefined variable. % set arr = (0 0 0 0 0 ) % @ arr[1] = (1) % @ arr[2] = ( $arr[1] + 4) % @ arr[3] = ( $arr[1] + 2) % @ arr[4] = ( $arr[3] * 2 ) % @ arr[5] = $arr[4] % echo $arr 1 5 3 6 6 % @ arr[5]++ % echo $arr 1 5 3 6 7
C shell syntax to access variables $#variable stores the no. of array elements $?variable =1, if variable declared, otherwise =0 $argv $#argv arguments of script no. of arguments of script
@ variable numeric operation on variable, n.b. mandatory space N.B. Variable must be created by set before usage