197 lines
3.4 KiB
Plaintext
197 lines
3.4 KiB
Plaintext
===============================
|
|
Commands
|
|
===============================
|
|
|
|
whoami
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name)))
|
|
|
|
===============================
|
|
Commands with arguments
|
|
===============================
|
|
|
|
cat file1.txt
|
|
git diff --word-diff=color -- file1.txt file2.txt
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name) (word))
|
|
(command (command_name) (word) (word) (word) (word) (word)))
|
|
|
|
===============================
|
|
Commands with quoted arguments
|
|
===============================
|
|
|
|
echo "hello $(whoami), this is $(uname)"
|
|
echo 'hi'
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name) (string
|
|
(command_substitution (command (command_name)))
|
|
(command_substitution (command (command_name)))))
|
|
(command (command_name) (raw_string)))
|
|
|
|
===============================
|
|
Quoted command names
|
|
===============================
|
|
|
|
"$a/$b" c
|
|
|
|
---
|
|
|
|
(program
|
|
(command (string (simple_expansion (variable_name)) (simple_expansion (variable_name))) (word)))
|
|
|
|
===============================
|
|
Commands with numeric arguments
|
|
===============================
|
|
|
|
exit 1
|
|
|
|
---
|
|
|
|
(program
|
|
(command (command_name) (word)))
|
|
|
|
===================================
|
|
Commands with environment variables
|
|
===================================
|
|
|
|
VAR1=1 ./script/test
|
|
VAR1=a VAR2="ok" git diff --word-diff=color
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(environment_variable_assignment (variable_name) (word))
|
|
(command_name))
|
|
(command
|
|
(environment_variable_assignment (variable_name) (word))
|
|
(environment_variable_assignment (variable_name) (string))
|
|
(command_name)
|
|
(word)
|
|
(word)))
|
|
|
|
===================================
|
|
Empty environment variables
|
|
===================================
|
|
|
|
VAR1=
|
|
VAR2= echo
|
|
|
|
---
|
|
|
|
(program
|
|
(environment_variable_assignment (variable_name))
|
|
(command (environment_variable_assignment (variable_name)) (command_name)))
|
|
|
|
===================================
|
|
Pipelines
|
|
===================================
|
|
|
|
whoami | cat
|
|
cat foo | grep -v bar
|
|
|
|
---
|
|
|
|
(program
|
|
(pipeline
|
|
(command (command_name))
|
|
(command (command_name)))
|
|
(pipeline
|
|
(command (command_name) (word))
|
|
(command (command_name) (word) (word))))
|
|
|
|
===================================
|
|
Lists
|
|
===================================
|
|
|
|
a | b && c && d; d e f || e g
|
|
|
|
---
|
|
|
|
(program
|
|
(list
|
|
(list
|
|
(pipeline
|
|
(command (command_name))
|
|
(command (command_name)))
|
|
(command (command_name)))
|
|
(command (command_name)))
|
|
(list
|
|
(command (command_name) (word) (word))
|
|
(command (command_name) (word))))
|
|
|
|
===============================
|
|
File redirects
|
|
===============================
|
|
|
|
whoami > /dev/null
|
|
cat a b > /dev/null
|
|
2>&1 whoami
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name)
|
|
(file_redirect (word)))
|
|
(command
|
|
(command_name)
|
|
(word)
|
|
(word)
|
|
(file_redirect (word)))
|
|
(command
|
|
(file_redirect (file_descriptor) (word))
|
|
(command_name)))
|
|
|
|
===============================
|
|
Heredoc redirects
|
|
===============================
|
|
|
|
node <<JS
|
|
console.log("hi")
|
|
JS
|
|
|
|
bash -c <<JS
|
|
echo hi
|
|
JS
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name)
|
|
(heredoc_redirect (heredoc)))
|
|
(command
|
|
(command_name)
|
|
(word)
|
|
(heredoc_redirect (heredoc))))
|
|
|
|
===============================
|
|
Heredocs with variables
|
|
===============================
|
|
|
|
node <<JS
|
|
a $B ${C}
|
|
JS
|
|
|
|
exit
|
|
|
|
---
|
|
|
|
(program
|
|
(command
|
|
(command_name)
|
|
(heredoc_redirect (heredoc
|
|
(simple_expansion (variable_name))
|
|
(expansion (variable_name)))))
|
|
(command (command_name)))
|