diff options
Diffstat (limited to 'guides/shell-workshop/shell.txt')
-rw-r--r-- | guides/shell-workshop/shell.txt | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/guides/shell-workshop/shell.txt b/guides/shell-workshop/shell.txt new file mode 100644 index 0000000..d98d249 --- /dev/null +++ b/guides/shell-workshop/shell.txt @@ -0,0 +1,131 @@ +introduce the shell interpreter + POSIX.1-2008 XCU 2.1 + shell reads input from: + a specified file, + '-c' option argument, or + stdin (interactive mode) + shell splits input lines into tokens and parses them + shell expands words + shell performs I/O redirection + shell executes functions, built-in commands, files, etc. +parameters and variables + positional parameters + POSIX.1-2008 XCU 2.5.1 + decimal numbers greater than 0, e.g. $1 and $2 + multiple-digit numbers should be enclosed in braces + assigned with: + shell arguments when shell starts + function arguments when a function is called + can be reassigned using 'set' built-in command + special parameters + POSIX.1-2008 XCU 2.5.2 + @ + all positional parameters + * + all positional parameters + # + number of positional parameters + ? + exit status of most recent command pipeline + - + current option flags + $ + process ID of shell + ! + process ID of most recent background command + 0 + name of shell or shell script + shell variables + POSIX.1-2008 XCU 2.5.3 + HOME + pathname of user's home directory + IFS + delimiters for field splitting + default: <space> <tab> <newline> + LINENO + line number of current script, if any + PATH + list of paths which should be searched for commands + PS1 + prompt value to be expanded and written to standard error + default value: "$ " + PWD + absolute pathname of the current working directory +word expansions + tilde expansion + POSIX.1-2008 XCU 2.6.1 + tilde-prefix: unquoted tilde at the beginning of a word + followed by all unquoted characters until first unquoted slash + login name is all characters in tilde-prefix following tilde + if login name is empty (tilde-prefix == "~") + expanded to value of HOME + else + expanded to home directory associated with login name + parameter expansion + POSIX.1-2008 XCU 2.6.2 + ${expression} or $expression + expression: + parameter + parameter:-word + parameter:=word + parameter:?word or parameter:? + parameter:+word + #parameter + parameter%word + parameter%%word + parameter#word + parameter##word + command substitution + POSIX.1-2008 XCU 2.6.3 + $(command) + or + `command` + expanding: + shell executes command in a subshell + shell replaces substitution with stdout of the command + newlines within command are allowed + nesting + `command1 \`command2 foo\` bar` + $(command1 $(command2 foo) bar) + arithmetic expansion + POSIX.1-2008 XCU 2.6.4 + $((expression)) + expanding: + shell processes expression + shell replaces substitution with value of the expression + arithmetic: + signed long integer precision + decimal, octal, and hexadecimal constants + e.g. 42, 052, 0x2A + operators: + ( ), unary +, unary -, +, -, *, /, % + ~, !, <<, >>, &, ^, | + <, <=, >, >= ==, !=, &&, ||, expr ? expr : expr + =, +=, -=, *=, /=, %=, <<=, >>=, &= ^=, |= + shell variables + if x has an integer value, then the following are equivalent: + $((x + 1)) $(($x + 1)) + field splitting + POSIX.1-2008 XCU 2.6.5 + IFS is a set of delimiters, at which unquoted fields are split + pathname expansion + POSIX.1-2008 XCU 2.6.6 + POSIX.1-2008 XCU 2.13 + performed unless 'set -f' was run + patterns + ? matches any single character + * matches multiple (0 or more) characters + [ opens RE bracket expansion + if pattern does not match any existing files + pattern string is left unchanged +redirection + input redirection + [n]<word + n: optional file descriptor number (default: 0, stdin) + word: name of file + output redirection + [n]>word + [n]>|word + n default: 1, stdout + appending redirected output + [n]>>word |