Bird
0
0

Which is the correct way to define a function named greet in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - Functions
Which is the correct way to define a function named greet in bash?
Afunction greet() { echo "Hello"; }
Bdef greet() { echo "Hello"; }
Cgreet() => { echo "Hello"; }
Dfunc greet() { echo "Hello"; }
Step-by-Step Solution
Solution:
  1. Step 1: Recall bash function syntax

    Bash functions use either function name() { } or name() { } syntax.
  2. Step 2: Check each option

    def greet() { echo "Hello"; } is Python syntax, greet() => { echo "Hello"; } is JavaScript arrow function syntax, func greet() { echo "Hello"; } uses invalid keyword. Only function greet() { echo "Hello"; } is valid bash syntax.
  3. Final Answer:

    function greet() { echo "Hello"; } -> Option A
  4. Quick Check:

    Bash function syntax = B [OK]
Quick Trick: Bash functions use 'function name() { }' or 'name() { }' [OK]
Common Mistakes:
MISTAKES
  • Using Python or JavaScript function syntax in bash
  • Missing parentheses after function name
  • Using 'func' keyword which is invalid in bash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes