Dit geeft de verschillen weer tussen de geselecteerde revisie en de huidige revisie van de pagina.
linux:commandos:sh_parse [2018/12/30 17:17] |
linux:commandos:sh_parse [2018/12/30 17:17] (huidige) |
||
---|---|---|---|
Regel 1: | Regel 1: | ||
+ | ====== Shell Command Line Parsing Sequence ====== | ||
+ | |||
+ | - Read the command line. | ||
+ | * Split the command line. Identify "tokens":<code> | ||
+ | <space> <tab> <newline> ; () <> | & "words" and "keywords"; command sequences, command grouping, pipelines. | ||
+ | </code> | ||
+ | * Perform a preliminary syntax check:<code> | ||
+ | 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 | ||
+ | </code> | ||
+ | * If the first "word" is a "non-opening keyword": issue a syntax error.<code> | ||
+ | fi, esac, then, else, do, done | ||
+ | </code> | ||
+ | * 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:<code> | ||
+ | ~ ~+ ~- ~username | ||
+ | </code> | ||
+ | - Perform variable substitution:<code> | ||
+ | $varname, ${varname} | ||
+ | </code> | ||
+ | - Perform command substitution:<code> | ||
+ | `cmd` (Bourne), $(cmd) (Korn/POSIX). | ||
+ | </code> | ||
+ | - Perform I/O-redirection:<code> | ||
+ | < 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 | ||
+ | </code> | ||
+ | - Korn/POSIX:Evaluate arithmetic expressions:<code> | ||
+ | let "..", (( .. )) | ||
+ | </code> | ||
+ | - Parse the command line into "words" via $IFS (space, tab, newline). | ||
+ | - Perform filename generation: interpret<code> | ||
+ | * ? [...] [!...] | ||
+ | </code> | ||
+ | - 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 | ||
+ | |||