0
0
Bash Scriptingscripting~10 mins

Custom exit codes (exit N) 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 exit the script with status 5.

Bash Scripting
exit [1]
Drag options to blanks, or click blank then click option'
A5
B0
C1
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using exit 0 which means success, not a custom code.
Forgetting to put a number after exit.
2fill in blank
medium

Complete the code to exit with status stored in variable code.

Bash Scripting
code=7
exit [1]
Drag options to blanks, or click blank then click option'
A${code}
Bcode
C$code
D"code"
Attempts:
3 left
💡 Hint
Common Mistakes
Using exit code which tries to exit with a command named 'code'.
Using quotes around variable name which makes it a string, not a number.
3fill in blank
hard

Fix the error in the script to exit with code 3 if count is less than 5.

Bash Scripting
count=3
if [ $count [1] 5 ]; then
  exit 3
fi
Drag options to blanks, or click blank then click option'
A>
B==
C-lt
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using == which tests equality, not less than.
Using = which is for assignment, not comparison.
4fill in blank
hard

Fill both blanks to exit with code 2 if status equals 1.

Bash Scripting
status=1
if [ $status [1] 1 ]; then
  exit [2]
fi
Drag options to blanks, or click blank then click option'
A==
B!=
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which means not equal.
Exiting with wrong code like 1 instead of 2.
5fill in blank
hard

Fill all three blanks to exit with code 4 if error is true and count is greater than 10.

Bash Scripting
error=true
count=15
if [ $error == true ] && [ $count [1] [2] ]; then
  exit [3]
fi
Drag options to blanks, or click blank then click option'
A>
B10
C4
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > for comparison.
Exiting with wrong code like 10 or 1.