Bird
0
0

Consider the script ./myscript.sh apple banana with this content:

medium📝 Command Output Q13 of 15
Bash Scripting - Variables
Consider the script ./myscript.sh apple banana with this content:
echo "$0"
echo "$1"
echo "$#"
echo "$@"
echo "$$"

What will be the output of the third line echo "$#"?
Amyscript.sh
B3
Capple
D2
Step-by-Step Solution
Solution:
  1. Step 1: Count the arguments passed

    The script is called with two arguments: 'apple' and 'banana'. So, the count is 2.
  2. Step 2: Understand what $# prints

    $# prints the number of arguments, which is 2 here.
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    Arguments count = 2 [OK]
Quick Trick: Count arguments after script name for $# [OK]
Common Mistakes:
MISTAKES
  • Counting script name as argument
  • Confusing $@ with $#
  • Expecting argument values instead of count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes