Gebruikershulpmiddelen

Site-hulpmiddelen


linux:commandos:sh_parse

Shell Command Line Parsing Sequence

  1. Read the command line.
    • Split the command line. Identify “tokens”:
      <space> <tab> <newline> ; () <> | & "words" and "keywords"; command sequences, command grouping, pipelines.
    • Perform a preliminary syntax check:
      quoting              : '...' "..." \...
      i/o-redirection      : < file, > file, >> file, 2> file, 2>> file, 2>&1
      conditional execution:   test,      [ ... ]     (Bourne)
                             [[ ... ]],  (( ... ))    (Korn/POSIX)
      background execution : &
      statement termination: (...) , {...}, if ... fi , case ... esac
      for/while/until ... done
    • If the first “word” is a “non-opening keyword”: issue a syntax error.
      fi, esac, then, else, do, done
    • If the command line is incomplete: display the “> ” prompt ($PS2).
      Then wait for the next return and read the command line again.
  2. If the -v option is in effect: print the command line as it is.
  3. Korn/POSIX:
    • If the first “word” is in the list of aliases: perform alias substitution.
    • If the value of the alias ends in space/tab, check the next “word” as well. If not, go on to the next step.
  4. Korn/POSIX: Perform tilde substitution:
    ~   ~+   ~-  ~username
  5. Perform variable substitution:
    $varname,  ${varname}
  6. Perform command substitution:
    `cmd` (Bourne),  $(cmd) (Korn/POSIX).
  7. Perform I/O-redirection:
    <  file           : open file for reading via file descriptor 0
    >  file,  >> file : open file for writing via file descriptor 1
    2> file, 2>> file : open file for writing via file descriptor 2
  8. Korn/POSIX:Evaluate arithmetic expressions:
    let "..", (( .. ))
  9. Parse the command line into “words” via $IFS (space, tab, newline).
  10. Perform filename generation: interpret
     *  ?  [...]  [!...]
  11. If the -x option is in effect: print the command line as it is now, preceding it with a + ($PS4).
  12. If the first word is a shell built-in or a function(Korn/POSIX) execute the command in the current environment.
    Else:
    1. Locate the command via $PATH.
    2. Determine the type of program. (UNIX command/shared executable or shell script)
    3. Execute the command in a new environment(child process)

.

Copyright (C) 2000 Integrated Services; tux4u.nl
Authors: Ing.J.M.Waldorp, Drs.M.Waldorp-Bonk sh_parse 20000809, 20110416

linux/commandos/sh_parse.txt · Laatst gewijzigd: 2018/12/30 17:17 (Externe bewerking)