0
0
Bash Scriptingscripting~10 mins

Shifting arguments (shift) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to shift the first argument out of the list.

Bash Scripting
#!/bin/bash

# Shift the first argument
shift [1]

echo "$1"
Drag options to blanks, or click blank then click option'
A1
B2
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shift 0' does not shift any arguments.
Using a negative number like 'shift -1' causes an error.
2fill in blank
medium

Complete the code to shift two arguments at once.

Bash Scripting
#!/bin/bash

# Shift two arguments
shift [1]

echo "$1"
Drag options to blanks, or click blank then click option'
A0
B1
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shift 1' only removes one argument.
Using 'shift 0' does not remove any arguments.
3fill in blank
hard

Fix the error in the code to correctly shift one argument.

Bash Scripting
#!/bin/bash

# Incorrect shift usage
shift [1]

echo "$1"
Drag options to blanks, or click blank then click option'
A-1
Bone
C1
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'one' or 'first' instead of numbers.
Using negative numbers like '-1'.
4fill in blank
hard

Fill both blanks to shift arguments and print the new first argument.

Bash Scripting
#!/bin/bash

# Shift arguments
shift [1]
echo [2]
Drag options to blanks, or click blank then click option'
A2
B"$1"
C"$2"
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Printing "$2" after shifting 2 arguments prints the wrong argument.
Using shift 1 but printing "$2" causes confusion.
5fill in blank
hard

Fill all three blanks to shift arguments and print the second argument after shifting.

Bash Scripting
#!/bin/bash

# Shift arguments
shift [1]
echo [2]
echo [3]
Drag options to blanks, or click blank then click option'
A1
B"$1"
C"$2"
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using shift 1 but printing $2 and $3 instead of $1 and $2.
Printing $1 twice instead of $1 and $2.