Bird
0
0

Which of the following is the correct way to define a bash function named display?

easy📝 Syntax Q3 of 15
Bash Scripting - Functions
Which of the following is the correct way to define a bash function named display?
Afunction display echo "Hello"
Bdisplay() { echo "Hello"; }
Cdef display() { echo "Hello"; }
Ddisplay { echo "Hello"; }
Step-by-Step Solution
Solution:
  1. Step 1: Identify valid bash function syntax

    Bash functions can be defined using the syntax name() { commands; }.
  2. Step 2: Evaluate options

    display() { echo "Hello"; } uses the correct syntax with parentheses and braces. function display echo "Hello" misses braces and uses incorrect syntax. def display() { echo "Hello"; } uses Python-like def which is invalid in bash. display { echo "Hello"; } misses parentheses.
  3. Final Answer:

    display() { echo "Hello"; } -> Option B
  4. Quick Check:

    Function syntax requires parentheses and braces [OK]
Quick Trick: Use name() { commands; } for bash functions [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses after function name
  • Using Python or other language syntax
  • Missing braces around function body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes