====== Shell Command Line Parsing Sequence ====== - Read the command line. * Split the command line. Identify "tokens": ; () <> | & "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. - If the -v option is in effect: print the command line as it is. - 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. - Korn/POSIX: Perform tilde substitution: ~ ~+ ~- ~username - Perform variable substitution: $varname, ${varname} - Perform command substitution: `cmd` (Bourne), $(cmd) (Korn/POSIX). - 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 - Korn/POSIX:Evaluate arithmetic expressions: let "..", (( .. )) - Parse the command line into "words" via $IFS (space, tab, newline). - Perform filename generation: interpret * ? [...] [!...] - If the -x option is in effect: print the command line as it is now, preceding it with a + ($PS4). - If the first word is a shell built-in or a function(Korn/POSIX) execute the command in the current environment. \\ Else: - Locate the command via $PATH. - Determine the type of program. (UNIX command/shared executable or shell script) - 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