Define show_status in a Bash script.
When called, it should print a status line.
Which definition is valid?
Bash supports function NAME { commands; }. The closing brace must follow a command terminator.
Detailed explanation
function show_status { printf '%s\n' ready; }Correct. function show_status { ...; } is valid Bash syntax.
Correct. function show_status { ...; } is valid Bash syntax.
function show_status = printf '%s\n' readyIncorrect. The body is not enclosed as a function definition.
Incorrect. The body is not enclosed as a function definition.
show_status := { printf '%s\n' ready; }Incorrect. := is not a Bash function-definition operator.
Incorrect. := is not a Bash function-definition operator.
def show_status: printf '%s\n' readyIncorrect. This is Python-style syntax, not Bash.
Incorrect. This is Python-style syntax, not Bash.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c "function show_status { printf '%s\\n' ready; }; show_status"Expected result
readyKey points
- Bash function keyword
- Body uses braces
- Call the function by name
Notes
- Environment: GNU Bash 5.2 / 一時シェル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.