Command-Line Parsing Order. Special Characters. Command Execution. Shell Variables
Command-Line Parsing Order. Special Characters. Command Execution. Shell Variables
Special characters.
Command execution.
Shell variables.
Motivation
Variables
A=Hello
A="Number of logged-in users:
Commands
ls la /
echo $A
finger | tail +2 | wc l
:(){ [ $1 -gt $2 ] && echo $1 || echo $2; }; : 1 3; : 2 1
Meta-characters
Characters that represent something other than its literal self (depending
on the context).
#, " '', , ` `, \, $, |, {}, (), [],
CTU - FIT
""
` cmd`
command substitution
CTU - FIT
Simple command
List
Pipeline
Compound command
( list ) { list ; } (( expression )) [[ expression ]] for while until if case.
CTU - FIT
Input/output Redirection
New process inherits file descriptors from his parent process by default.
User can redefine/redirect every file descriptor by special characters.
CTU - FIT
CTU - FIT
CTU - FIT
cmd1 ; cmd2
( cmd1 ; cmd2 )
{ cmd1 ; cmd2 ; }
CTU - FIT
(pipe/pipeline)
The standard output of cmd1 is connected via
a pipe to the standard input of cmd2.
Commands are executed in parallel.
The return status of a pipeline is the exit
status of the last command.
cmd1 || cmd2
CTU - FIT
Aliases
Directory name abbreviation ~ (tilde)
~
Home directory of the current user (except of sh)
~username Home directory of the given user (except of sh)
Command substitutions
` cmd `
Shell performs the expansion by executing cmd
and replacing the command substitution with the
standard output of the cmd.
CTU - FIT
(except of sh)
10
CTU - FIT
11
?
[abc]
[a-z]
[!abc] [!a-z]
[^ijk] [^m-z]
CTU - FIT
12
First, the shell interprets the command line when it passes to the eval
command.
13
Command Execution
Shell function
CTU - FIT
14
Shell Variables
variable=value
export variable[=value]
$variable
set [variable]
env
defines prompt
$PAGER
$PATH
$MANPATH
CTU - FIT
15
Shell Variables
home directory
PWD
program name
1,,9
CTU - FIT
16