tree-sitter-bash/corpus/control_flow.txt

135 lines
2.4 KiB
Plaintext

====================================
While statements
====================================
while something happens; do
echo a
echo b
done
---
(program
(while_statement
(command (command_name) (word))
(do_group
(command (command_name) (word))
(command (command_name) (word)))))
====================================
For statements
====================================
for a in $(seq 1 10); do
echo $a
done
---
(program
(for_statement
(word)
(command (command_substitution (command (command_name) (word) (word))))
(do_group
(command (command_name) (simple_expansion (variable_name))))))
====================================
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) (word))
(command (command_name) (word) (word)))
(command (command_name) (word))
(elif_clause
(pipeline
(command (command_name) (word))
(command (command_name) (word) (word)))
(command (command_name) (word)))
(else_clause
(command (command_name)))))
====================================
If statements with conditional expressions
====================================
if [ "$(uname)" == 'Darwin' ]; then
echo one
fi
---
(program
(if_statement
(bracket_command
(string (command_substitution (command (command_name))))
(word)
(raw_string))
(command (command_name) (word))))
====================================
Case statements
====================================
case "opt" in
a)
echo a
;;
b)
echo b
;;
esac
---
(program
(case_statement (string)
(case_item (word)
(command (command_name) (word)))
(case_item (word)
(command (command_name) (word)))))
===============================
Subshells
===============================
(
./start-server --port=80
) &
---
(program
(subshell (command (command_name) (word))))
===============================
Function definitions
===============================
do_something() {
echo ok
}
function do_something_else() {
echo ok
}
---
(program
(function_definition (command_name) (compound_statement (command (command_name) (word))))
(function_definition (command_name) (compound_statement (command (command_name) (word)))))