Text-only Table of Contents (frame/ no frame)
(5) UNIX Shells Previous Top Next

UNIX Shells

Interpreting the command line

(where do the spaces go ?)

These comments apply to all the common shells. Exact syntax of internal shell commands differ between shells. Command lines given to a shell for processing (typed at prompt, or out of a shell script file) are interpreted as follows (somewhat simplified): (more on this in the shell programming class)
  1. Separate words by whitespace (space, tab). Quotes override this.
  2. Expand shell aliases (csh/tcsh/ksh only)
  3. Expand shell and environment variables ($VAR, e.g. $HOME, $PRINTER
  4. Expand filename wildcards *?[] into a sorted list of matching filenames (pathnames).
  5. Look for I/O redirection and open the named files for input/output ( >> outfile ). Remove these items - the program does not see this information
  6. Run any commands in "`" and substitute the output. (echo `date`)
  7. Evaluate shell internal commands (e.g. echo, cd)
  8. If not an internal command, the first word on the line is assumed to be an external command, and is search for by examining the $PATH variable left to right. The first match is what gets executed (which ls)
  9. Anything else left (typically option flags and filenames) are passed to the command as arguments.

    Most commands take optional flags introduced by a "-". How the arguments are interpreted is up to each individual program, but most programs accept filename arguments in a predictable way, or attempt to do something natural with standard input if no filename arguments are present.
    Example:
    ls
    ls *
    setenv LSFLAGS -lF
    ls $LSFLAGS

    Previous Top Next


    slide05.src  last modified Feb 8, 2011 Introduction Table of Contents
    (frame/no frame)
    Printable
    (single file)
    © Dartmouth College