Bird
0
0

Consider this script run as ./script.sh a b c d e:

medium📝 Command Output Q5 of 15
Bash Scripting - User Input
Consider this script run as ./script.sh a b c d e:
#!/bin/bash
shift
shift 2
echo "$1 $2"

What is the output?
Aa b
Bb c
Cc d
Dd e
Step-by-Step Solution
Solution:
  1. Step 1: Initial arguments

    $1=a, $2=b, $3=c, $4=d, $5=e.
  2. Step 2: Apply first shift

    Removes 'a', now $1=b, $2=c, $3=d, $4=e.
  3. Step 3: Apply shift 2

    Removes 'b' and 'c', now $1=d, $2=e.
  4. Final Answer:

    d e -> Option D
  5. Quick Check:

    Multiple shifts remove correct args [OK]
Quick Trick: Multiple shifts add up to total removed args [OK]
Common Mistakes:
MISTAKES
  • Not adding shifts correctly
  • Assuming shifts reset arguments
  • Confusing argument positions after multiple shifts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes