tree-sitter-bash/corpus/control_flow.txt

118 lines
2.1 KiB
Plaintext

====================================
While statements
====================================
while something happens; do
echo a
echo b
done
---
(program
(while_statement
(command (command_name) (argument))
(do_group
(command (command_name) (argument))
(command (command_name) (argument)))))
====================================
If statements
====================================
if cat some_file | grep -v ok; then
echo one
elif cat other_file | grep -v ok; then
echo two
else
exit
fi
---
(program
(if_statement
(pipeline
(command (command_name) (argument))
(command (command_name) (argument) (argument)))
(command (command_name) (argument))
(elif_clause
(pipeline
(command (command_name) (argument))
(command (command_name) (argument) (argument)))
(command (command_name) (argument)))
(else_clause
(command (command_name)))))
====================================
If statements with conditional expressions
====================================
if [ "$(uname)" == 'Darwin' ]; then
echo one
fi
---
(program
(if_statement
(bracket_command
(quoted_argument (command_substitution (command (command_name))))
(argument)
(single_quoted_argument))
(command (command_name) (argument))))
====================================
Case statements
====================================
case "opt" in
a)
echo a
;;
b)
echo b
;;
esac
---
(program
(case_statement (quoted_argument)
(case_item (argument)
(command (command_name) (argument)))
(case_item (argument)
(command (command_name) (argument)))))
===============================
Subshells
===============================
(
./start-server --port=80
) &
---
(program
(subshell (command (command_name) (argument))))
===============================
Function definitions
===============================
do_something() {
echo ok
}
function do_something_else() {
echo ok
}
---
(program
(function_definition (command_name) (compound_command (command (command_name) (argument))))
(function_definition (command_name) (compound_command (command (command_name) (argument)))))