Google


/etc/passwd 27 % grep -c nsh$ /etc/passwd 128 % grep  -c  -v  sh$
/etc/passwd  430  %  Since these commands are very similar we can
use to do this more easily.  % foreach i ('sh$' 'csh$' '-v  sh$')
?  grep  -c  $i /etc/passwd ? end 27 128 430 % Note here that the
shell prompts for input with `? ' when reading the  body  of  the
loop.   Very  useful with loops are variables which contain lists
of filenames or other words.  You can,  for  example,  do  %  set
a=(`ls`)  % echo $a csh.n csh.rm % ls csh.n csh.rm % echo $#a 2 %
The command here gave the variable a list of all the filenames in
the  current  directory as value.  We can then iterate over these
names to perform any chosen function.  The output  of  a  command
within  ``'  characters  is  converted  by the shell to a list of
words.  You can also place the ``' quoted string within `"' char-
acters  to take each (non-empty) line as a component of the vari-
able; preventing the lines from being split into words at  blanks
and  tabs.  A modifier `:x' exists which can be used later to ex-
pand each component of the variable into another variable  split-
ting  it into separate words at embedded blanks and tabs.  Braces
{ ... } in argument expansion Another form of filename expansion,
alluded  to  before  involves  the characters `{' and `}'.  These
characters specify that the contained strings, separated  by  `,'
are  to  be consecutively substituted into the containing charac-
ters  and   the   results   expanded   left   to   right.    Thus
A{str1,str2,...strn}B  expands  to  Astr1B Astr2B ... AstrnB This
expansion occurs before the other filename expansions, and may be
applied  recursively (i.e. nested).  The results of each expanded
string are sorted separately, left  to  right  order  being  pre-
served.   The resulting filenames are not required to exist if no
other expansion mechanisms are used.  This means that this mecha-
nism  can  be used to generate arguments which are not filenames,
but which have common parts.  A typical  use  of  this  would  be
mkdir   ~/{hdrs,retrofit,csh}   to  make  subdirectories  `hdrs',
`retrofit' and `csh' in your home directory.  This  mechanism  is
most  useful  when the common prefix is longer than in this exam-
ple, i.e.   chown  root  /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
Command  substitution A command enclosed in ``' characters is re-
placed, just before filenames are expanded, by  the  output  from
that  command.   Thus  it is possible to do set pwd=`pwd` to save
the current directory in the variable or to do ex `grep -l  TRACE
*.c`  to  run the editor supplying as arguments those files whose
names end in `.c' which have the string `TRACE' in them.*   *Com-
mand  expansion  also  occurs  in  input redirected with `<<' and
within `"' quotations.  Refer to the  shell  manual  section  for
full  details.  Other details not covered here In particular cir-
cumstances it may be necessary to know the exact nature and order
of  different  substitutions  performed  by the shell.  The exact
meaning of certain combinations of quotations is also occasional-
ly  important.   These  are detailed fully in its manual section.
The shell has a number of command line option flags mostly of use
in  writing  UNIX programs, and debugging shell scripts.  See the
csh(1) manual section for a list of these options.






















































Man(1) output converted with man2html