Bird
0
0

In a bash function, what does $1 represent?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Functions
In a bash function, what does $1 represent?
AThe first argument passed to the function
BThe name of the function
CThe total number of arguments passed to the script
DThe exit status of the last command
Step-by-Step Solution
Solution:
  1. Step 1: Understand function arguments in bash

    Inside a bash function, $1 refers to the first argument passed specifically to that function, not the script.
  2. Step 2: Differentiate from script arguments

    The script's arguments are accessed outside functions, but inside a function, $1 resets to the function's first argument.
  3. Final Answer:

    The first argument passed to the function -> Option A
  4. Quick Check:

    $1 in function = first function argument [OK]
Quick Trick: Inside functions, $1 is the first function argument, not script's [OK]
Common Mistakes:
MISTAKES
  • Confusing $1 inside function with script's $1
  • Thinking $1 is function name
  • Mixing $1 with number of arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes