tree-sitter-bash/corpus/control_flow.txt

87 lines
1.6 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)))))