170 lines
3.4 KiB
Plaintext
170 lines
3.4 KiB
Plaintext
=============================
|
|
Literal words
|
|
=============================
|
|
|
|
echo a
|
|
echo a b
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name (word)) (word))
|
|
(command (command_name (word)) (word) (word)))
|
|
|
|
=============================
|
|
Simple variable expansions
|
|
=============================
|
|
|
|
echo $abc
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name (word)) (simple_expansion (variable_name))))
|
|
|
|
=============================
|
|
Variable expansions
|
|
=============================
|
|
|
|
echo ${abc}
|
|
echo ${abc:-def}
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name (word)) (expansion (variable_name)))
|
|
(command (command_name (word)) (expansion (variable_name) (word))))
|
|
|
|
===================================
|
|
Other variable expansion operators
|
|
===================================
|
|
|
|
cat ${BAR} ${ABC=def} ${GHI:?jkl}
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name (word))
|
|
(expansion (variable_name))
|
|
(expansion (variable_name) (word))
|
|
(expansion (variable_name) (word))))
|
|
|
|
=============================
|
|
Command substitutions
|
|
=============================
|
|
|
|
echo `echo hi`
|
|
echo $(echo $(echo hi))
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name (word))
|
|
(command_substitution (command (command_name (word)) (word))))
|
|
(command
|
|
(command_name (word))
|
|
(command_substitution (command
|
|
(command_name (word))
|
|
(command_substitution (command
|
|
(command_name (word))
|
|
(word)))))))
|
|
|
|
=============================
|
|
Process substitutions
|
|
=============================
|
|
|
|
wc -c <(echo abc && echo def)
|
|
echo abc > >(wc -c)
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name (word))
|
|
(word)
|
|
(process_substitution (list
|
|
(command (command_name (word)) (word))
|
|
(command (command_name (word)) (word)))))
|
|
(command
|
|
(command_name (word))
|
|
(word)
|
|
(file_redirect (process_substitution
|
|
(command (command_name (word)) (word))))))
|
|
|
|
=============================
|
|
Single quoted strings
|
|
=============================
|
|
|
|
echo 'a b' 'c d'
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name (word)) (raw_string) (raw_string)))
|
|
|
|
=============================
|
|
Double quoted strings
|
|
=============================
|
|
|
|
echo "a" "b"
|
|
echo "a ${b} c" "d $e"
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name (word))
|
|
(string)
|
|
(string))
|
|
(command (command_name (word))
|
|
(string (expansion (variable_name)))
|
|
(string (simple_expansion (variable_name)))))
|
|
|
|
=========================================
|
|
Strings containing command substitutions
|
|
=========================================
|
|
|
|
find "`dirname $file`" -name "$base"'*'
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name (word))
|
|
(string (command_substitution (command (command_name (word)) (simple_expansion (variable_name)))))
|
|
(word)
|
|
(concatenation
|
|
(string (simple_expansion (variable_name)))
|
|
(raw_string))))
|
|
|
|
=========================================
|
|
Arrays and array expansions
|
|
=========================================
|
|
|
|
a=()
|
|
b=(1 2 3)
|
|
|
|
echo ${a[@]}
|
|
echo ${#b[@]}
|
|
|
|
a[$i]=50
|
|
a+=(foo "bar" $(baz))
|
|
|
|
---
|
|
|
|
(program
|
|
(environment_variable_assignment (variable_name) (array))
|
|
(environment_variable_assignment (variable_name) (array (word) (word) (word)))
|
|
(command (command_name (word)) (expansion (variable_name)))
|
|
(command (command_name (word)) (expansion (variable_name)))
|
|
(environment_variable_assignment
|
|
(subscript (variable_name) (simple_expansion (variable_name)))
|
|
(word))
|
|
(environment_variable_assignment
|
|
(variable_name)
|
|
(array
|
|
(word)
|
|
(string)
|
|
(command_substitution (command (command_name (word)))))))
|