Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shift 0' does not shift any arguments.
Using a negative number like 'shift -1' causes an error.
✗ Incorrect
Using 'shift 1' removes the first argument, so $1 becomes the second argument.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shift 1' only removes one argument.
Using 'shift 0' does not remove any arguments.
✗ Incorrect
Using 'shift 2' removes the first two arguments, so $1 becomes the third argument.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'one' or 'first' instead of numbers.
Using negative numbers like '-1'.
✗ Incorrect
The 'shift' command requires a positive integer number, so '1' is correct.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Printing "$2" after shifting 2 arguments prints the wrong argument.
Using shift 1 but printing "$2" causes confusion.
✗ Incorrect
Shifting by 2 removes first two arguments, so $1 is the new first argument to print.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Shifting by 2 removes first two arguments, so $1 and $2 are the new first and second arguments.