Bird
0
0

Which of the following is the correct way to print the first argument passed to a bash script?

easy📝 Syntax Q12 of 15
Bash Scripting - Variables
Which of the following is the correct way to print the first argument passed to a bash script?
Aecho $1
Becho $0
Cecho $#
Decho $$
Step-by-Step Solution
Solution:
  1. Step 1: Identify the variable for the first argument

    $1 holds the first argument passed to the script.
  2. Step 2: Check other options

    $0 is the script name, $# is the argument count, and $$ is the script's process ID, so they are incorrect for printing the first argument.
  3. Final Answer:

    echo $1 -> Option A
  4. Quick Check:

    First argument = $1 [OK]
Quick Trick: Use $1 to access the first argument in bash scripts [OK]
Common Mistakes:
MISTAKES
  • Using $0 instead of $1 for first argument
  • Confusing $# with argument value
  • Trying to print $$ for argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes