Bird
0
0

What does $1 represent in a bash script?

easy🧠 Conceptual Q11 of 15
Bash Scripting - User Input
What does $1 represent in a bash script?
AThe last command-line argument passed to the script
BThe total number of arguments passed to the script
CThe name of the script file
DThe first command-line argument passed to the script
Step-by-Step Solution
Solution:
  1. Step 1: Understand command-line arguments in bash

    In bash scripts, $1 refers to the first argument given after the script name.
  2. Step 2: Differentiate from other special variables

    $# is the count of arguments, $0 is the script name, and $@ is all arguments.
  3. Final Answer:

    The first command-line argument passed to the script -> Option D
  4. Quick Check:

    $1 = first argument [OK]
Quick Trick: Remember $1 is always the first argument after script name [OK]
Common Mistakes:
MISTAKES
  • Confusing $1 with $# (argument count)
  • Thinking $1 is the script name
  • Mixing $1 with $0 or $@

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes