2017-07-14 19:28:54 +00:00
|
|
|
===============================
|
|
|
|
Commands
|
|
|
|
===============================
|
|
|
|
|
|
|
|
whoami
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-17 17:19:35 +00:00
|
|
|
(command (command_name (word))))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
|
|
|
===============================
|
|
|
|
Commands with arguments
|
|
|
|
===============================
|
|
|
|
|
|
|
|
cat file1.txt
|
2017-07-16 05:13:55 +00:00
|
|
|
git diff --word-diff=color -- file1.txt file2.txt
|
2017-07-14 19:28:54 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-17 17:19:35 +00:00
|
|
|
(command (command_name (word)) (word))
|
|
|
|
(command (command_name (word)) (word) (word) (word) (word) (word)))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
2017-07-15 00:32:55 +00:00
|
|
|
===============================
|
|
|
|
Quoted command names
|
|
|
|
===============================
|
|
|
|
|
|
|
|
"$a/$b" c
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-17 17:19:35 +00:00
|
|
|
(command
|
|
|
|
(command_name (string (simple_expansion (variable_name)) (simple_expansion (variable_name))))
|
|
|
|
(word)))
|
2017-07-15 00:32:55 +00:00
|
|
|
|
2017-07-15 00:14:23 +00:00
|
|
|
===============================
|
|
|
|
Commands with numeric arguments
|
|
|
|
===============================
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2017-07-17 17:19:35 +00:00
|
|
|
(command (command_name (word)) (word)))
|
2017-07-15 00:14:23 +00:00
|
|
|
|
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
|
2018-02-27 21:22:28 +00:00
|
|
|
(variable_assignment (variable_name) (word))
|
2017-07-17 17:19:35 +00:00
|
|
|
(command_name (word)))
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2018-02-27 21:22:28 +00:00
|
|
|
(variable_assignment (variable_name) (word))
|
|
|
|
(variable_assignment (variable_name) (string))
|
2017-07-17 17:19:35 +00:00
|
|
|
(command_name (word))
|
2017-07-16 05:13:55 +00:00
|
|
|
(word)
|
|
|
|
(word)))
|
2017-07-14 19:28:54 +00:00
|
|
|
|
2017-07-15 00:41:14 +00:00
|
|
|
===================================
|
|
|
|
Empty environment variables
|
|
|
|
===================================
|
|
|
|
|
|
|
|
VAR1=
|
|
|
|
VAR2= echo
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2018-02-27 21:22:28 +00:00
|
|
|
(variable_assignment (variable_name))
|
|
|
|
(command (variable_assignment (variable_name)) (command_name (word))))
|
2017-07-15 00:41:14 +00:00
|
|
|
|
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
|
2018-10-18 18:05:58 +00:00
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)))
|
2017-07-16 05:13:55 +00:00
|
|
|
(file_redirect (word)))
|
2018-10-18 18:05:58 +00:00
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)) (word) (word))
|
2017-07-16 05:13:55 +00:00
|
|
|
(file_redirect (word)))
|
2017-07-14 23:11:35 +00:00
|
|
|
(command
|
2017-07-16 05:13:55 +00:00
|
|
|
(file_redirect (file_descriptor) (word))
|
2017-07-17 17:19:35 +00:00
|
|
|
(command_name (word))))
|
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
|
2018-10-18 18:05:58 +00:00
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)))
|
|
|
|
(heredoc_redirect (heredoc_start)))
|
|
|
|
(heredoc_body)
|
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)) (word))
|
|
|
|
(heredoc_redirect (heredoc_start)))
|
|
|
|
(heredoc_body))
|
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
|
2018-10-18 18:05:58 +00:00
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)))
|
|
|
|
(heredoc_redirect (heredoc_start)))
|
|
|
|
(heredoc_body
|
|
|
|
(simple_expansion (variable_name))
|
|
|
|
(expansion (variable_name)))
|
2017-07-17 17:19:35 +00:00
|
|
|
(command (command_name (word))))
|
2018-03-29 16:54:05 +00:00
|
|
|
|
|
|
|
=================================
|
|
|
|
Heredocs with file redirects
|
|
|
|
================================
|
|
|
|
|
|
|
|
cat <<EOF > $tmpfile
|
|
|
|
a $B ${C}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
wc -l $tmpfile
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
2018-10-18 18:05:58 +00:00
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)))
|
2019-04-18 22:25:40 +00:00
|
|
|
(heredoc_redirect (heredoc_start))
|
|
|
|
(file_redirect (simple_expansion (variable_name))))
|
2018-10-18 18:05:58 +00:00
|
|
|
(heredoc_body
|
|
|
|
(simple_expansion (variable_name))
|
|
|
|
(expansion (variable_name)))
|
2018-03-29 16:54:05 +00:00
|
|
|
(command
|
|
|
|
(command_name (word))
|
|
|
|
(word)
|
|
|
|
(simple_expansion (variable_name))))
|
2018-10-18 18:12:43 +00:00
|
|
|
|
2019-04-18 22:25:40 +00:00
|
|
|
=================================
|
|
|
|
Heredocs with pipes
|
|
|
|
================================
|
|
|
|
|
|
|
|
one <<EOF | grep two
|
|
|
|
three
|
|
|
|
EOF
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(pipeline
|
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)))
|
|
|
|
(heredoc_redirect (heredoc_start)))
|
|
|
|
(command (command_name (word)) (word)))
|
|
|
|
(heredoc_body))
|
|
|
|
|
2018-10-18 18:12:43 +00:00
|
|
|
======================================
|
|
|
|
Heredocs with escaped expansions
|
|
|
|
======================================
|
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
DEV_NAME=\$(lsblk)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program (redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body))
|
2018-10-18 18:24:08 +00:00
|
|
|
|
|
|
|
======================================
|
|
|
|
Quoted Heredocs
|
|
|
|
======================================
|
|
|
|
|
|
|
|
cat << 'EOF'
|
|
|
|
a=$b
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat << "EOF"
|
|
|
|
a=$b
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat << \EOF
|
|
|
|
EOF
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body)
|
|
|
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body (simple_expansion (variable_name)))
|
|
|
|
(redirected_statement (command (command_name (word))) (heredoc_redirect (heredoc_start))) (heredoc_body))
|
2018-10-19 20:06:56 +00:00
|
|
|
|
|
|
|
==========================================
|
|
|
|
Heredocs with indented closing delimiters
|
|
|
|
==========================================
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat <<-EOF
|
|
|
|
Usage: ${0##*/} FOO BAR
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
(program
|
|
|
|
(function_definition
|
|
|
|
(word)
|
|
|
|
(compound_statement
|
|
|
|
(redirected_statement
|
|
|
|
(command (command_name (word)))
|
|
|
|
(heredoc_redirect (heredoc_start)))
|
|
|
|
(heredoc_body (expansion (special_variable_name) (word))))))
|