2017-07-14 19:28:54 +00:00
|
|
|
===============================
|
|
|
|
Commands
|
|
|
|
===============================
|
|
|
|
|
|
|
|
whoami
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command (command_name)))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
|
|
|
===============================
|
|
|
|
Commands with arguments
|
|
|
|
===============================
|
|
|
|
|
|
|
|
cat file1.txt
|
|
|
|
cat -n file1.txt file2.txt
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command (command_name) (argument))
|
|
|
|
(command (command_name) (argument) (argument) (argument)))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
2017-07-14 23:47:25 +00:00
|
|
|
===============================
|
2017-07-15 00:14:23 +00:00
|
|
|
Commands with quoted arguments
|
2017-07-14 23:47:25 +00:00
|
|
|
===============================
|
|
|
|
|
|
|
|
echo "hello $(whoami), this is $(uname)"
|
|
|
|
echo 'hi'
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(command (command_name) (quoted_argument
|
|
|
|
(command_substitution (command (command_name)))
|
|
|
|
(command_substitution (command (command_name)))))
|
|
|
|
(command (command_name) (single_quoted_argument)))
|
|
|
|
|
2017-07-15 00:32:55 +00:00
|
|
|
===============================
|
|
|
|
Quoted command names
|
|
|
|
===============================
|
|
|
|
|
|
|
|
"$a/$b" c
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(command (quoted_argument (expansion (variable_name)) (expansion (variable_name))) (argument)))
|
|
|
|
|
2017-07-15 00:14:23 +00:00
|
|
|
===============================
|
|
|
|
Commands with numeric arguments
|
|
|
|
===============================
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(command (command_name) (argument)))
|
|
|
|
|
2017-07-14 19:28:54 +00:00
|
|
|
===================================
|
|
|
|
Commands with environment variables
|
|
|
|
===================================
|
|
|
|
|
|
|
|
VAR1=1 ./script/test
|
|
|
|
VAR1=a VAR2="ok" git diff --word-diff=color
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-14 19:28:54 +00:00
|
|
|
(environment_variable_assignment (variable_name) (argument))
|
2017-07-14 23:11:35 +00:00
|
|
|
(command_name))
|
|
|
|
(command
|
2017-07-14 19:28:54 +00:00
|
|
|
(environment_variable_assignment (variable_name) (argument))
|
2017-07-14 23:47:25 +00:00
|
|
|
(environment_variable_assignment (variable_name) (quoted_argument))
|
2017-07-14 19:28:54 +00:00
|
|
|
(command_name)
|
|
|
|
(argument)
|
2017-07-14 23:11:35 +00:00
|
|
|
(argument)))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
2017-07-15 00:41:14 +00:00
|
|
|
===================================
|
|
|
|
Empty environment variables
|
|
|
|
===================================
|
|
|
|
|
|
|
|
VAR1=
|
|
|
|
VAR2= echo
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(environment_variable_assignment (variable_name))
|
|
|
|
(command (environment_variable_assignment (variable_name)) (command_name)))
|
|
|
|
|
2017-07-14 19:28:54 +00:00
|
|
|
===================================
|
|
|
|
Pipelines
|
|
|
|
===================================
|
|
|
|
|
|
|
|
whoami | cat
|
|
|
|
cat foo | grep -v bar
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(pipeline
|
|
|
|
(command (command_name))
|
|
|
|
(command (command_name)))
|
|
|
|
(pipeline
|
|
|
|
(command (command_name) (argument))
|
|
|
|
(command (command_name) (argument) (argument))))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
|
|
|
===================================
|
|
|
|
Lists
|
|
|
|
===================================
|
|
|
|
|
2017-07-14 23:11:35 +00:00
|
|
|
a | b && c && d; d e f || e g
|
2017-07-14 19:28:54 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(list
|
2017-07-14 19:28:54 +00:00
|
|
|
(list
|
|
|
|
(pipeline
|
2017-07-14 23:11:35 +00:00
|
|
|
(command (command_name))
|
|
|
|
(command (command_name)))
|
|
|
|
(command (command_name)))
|
|
|
|
(command (command_name)))
|
|
|
|
(list
|
|
|
|
(command (command_name) (argument) (argument))
|
|
|
|
(command (command_name) (argument))))
|
2017-07-14 19:43:42 +00:00
|
|
|
|
|
|
|
===============================
|
|
|
|
File redirects
|
|
|
|
===============================
|
|
|
|
|
|
|
|
whoami > /dev/null
|
2017-07-15 00:14:23 +00:00
|
|
|
cat a b > /dev/null
|
2017-07-14 19:43:42 +00:00
|
|
|
2>&1 whoami
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-14 19:43:42 +00:00
|
|
|
(command_name)
|
2017-07-15 00:14:23 +00:00
|
|
|
(file_redirect (argument)))
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-14 19:43:42 +00:00
|
|
|
(command_name)
|
|
|
|
(argument)
|
|
|
|
(argument)
|
2017-07-15 00:14:23 +00:00
|
|
|
(file_redirect (argument)))
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-15 00:14:23 +00:00
|
|
|
(file_redirect (file_descriptor) (argument))
|
2017-07-14 23:11:35 +00:00
|
|
|
(command_name)))
|
2017-07-14 20:00:41 +00:00
|
|
|
|
2017-07-14 20:54:05 +00:00
|
|
|
===============================
|
2017-07-14 23:11:35 +00:00
|
|
|
Variable expansions
|
2017-07-14 20:54:05 +00:00
|
|
|
===============================
|
|
|
|
|
2017-07-14 23:11:35 +00:00
|
|
|
cat $FOO
|
2017-07-14 20:54:05 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-14 20:54:05 +00:00
|
|
|
(command_name)
|
2017-07-14 23:11:35 +00:00
|
|
|
(expansion (variable_name))))
|
2017-07-14 20:54:05 +00:00
|
|
|
|
2017-07-14 21:27:13 +00:00
|
|
|
===============================
|
2017-07-14 23:11:35 +00:00
|
|
|
Variable expansion operators
|
2017-07-14 21:27:13 +00:00
|
|
|
===============================
|
|
|
|
|
2017-07-14 23:11:35 +00:00
|
|
|
cat ${BAR} ${ABC=def} ${GHI:?jkl}
|
2017-07-14 21:27:13 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-14 21:27:13 +00:00
|
|
|
(command_name)
|
2017-07-14 23:11:35 +00:00
|
|
|
(operator_expansion (variable_name))
|
|
|
|
(operator_expansion (variable_name) (argument))
|
|
|
|
(operator_expansion (variable_name) (argument))))
|
2017-07-14 21:27:13 +00:00
|
|
|
|
2017-07-14 20:00:41 +00:00
|
|
|
===============================
|
2017-07-14 23:11:35 +00:00
|
|
|
Heredoc redirects
|
2017-07-14 20:00:41 +00:00
|
|
|
===============================
|
|
|
|
|
2017-07-14 23:11:35 +00:00
|
|
|
node <<JS
|
|
|
|
console.log("hi")
|
|
|
|
JS
|
|
|
|
|
|
|
|
bash -c <<JS
|
|
|
|
echo hi
|
|
|
|
JS
|
2017-07-14 20:00:41 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
|
|
|
(command_name)
|
|
|
|
(heredoc_redirect (heredoc)))
|
|
|
|
(command
|
2017-07-14 20:00:41 +00:00
|
|
|
(command_name)
|
2017-07-14 23:11:35 +00:00
|
|
|
(argument)
|
|
|
|
(heredoc_redirect (heredoc))))
|
2017-07-14 20:00:41 +00:00
|
|
|
|
|
|
|
===============================
|
2017-07-14 23:11:35 +00:00
|
|
|
Heredocs with variables
|
2017-07-14 20:00:41 +00:00
|
|
|
===============================
|
|
|
|
|
2017-07-14 23:11:35 +00:00
|
|
|
node <<JS
|
|
|
|
a $B ${C}
|
|
|
|
JS
|
|
|
|
|
|
|
|
exit
|
2017-07-14 20:00:41 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-14 20:00:41 +00:00
|
|
|
(command_name)
|
2017-07-14 23:11:35 +00:00
|
|
|
(heredoc_redirect (heredoc
|
|
|
|
(expansion (variable_name))
|
|
|
|
(operator_expansion (variable_name)))))
|
|
|
|
(command (command_name)))
|