Bird
0
0

Which of the following is the correct way to access the first argument inside a bash function named myfunc?

easy📝 Syntax Q3 of 15
Bash Scripting - Functions
Which of the following is the correct way to access the first argument inside a bash function named myfunc?
AUse <code>first_arg</code> inside the function
BUse <code>$1</code> inside the function
CUse <code>arg[1]</code> inside the function
DUse <code>$arg1</code> inside the function
Step-by-Step Solution
Solution:
  1. Step 1: Recall bash function argument syntax

    Bash functions use positional parameters like $1, $2 to access arguments.
  2. Step 2: Identify the correct syntax for first argument

    The first argument is always accessed with $1, no other variable names are used by default.
  3. Final Answer:

    Use $1 inside the function -> Option B
  4. Quick Check:

    First argument = $1 [OK]
Quick Trick: Use $1 for first argument inside bash functions [OK]
Common Mistakes:
MISTAKES
  • Using variable names like $arg1 instead of $1
  • Trying to access arguments as arrays
  • Confusing shell variables with function arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes