Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a read-only variable named MY_VAR with value 10.
Bash Scripting
readonly [1]=10
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'readonly' as the variable name.
Using lowercase variable names when uppercase is expected.
✗ Incorrect
The readonly command followed by the variable name MY_VAR makes it read-only.
2fill in blank
mediumComplete the code to print the value of the read-only variable MY_VAR.
Bash Scripting
echo [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the dollar sign before the variable name.
Using variable name without braces which can cause errors in some contexts.
✗ Incorrect
Use ${MY_VAR} to correctly reference the variable value in bash.
3fill in blank
hardFix the error in the code that tries to change a read-only variable MY_VAR to 20.
Bash Scripting
readonly MY_VAR=10 [1] MY_VAR=20
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign a new value directly to a readonly variable.
Using 'export' which does not remove readonly status.
✗ Incorrect
You cannot assign a new value to a read-only variable. You must unset it first to remove the read-only attribute.
4fill in blank
hardFill both blanks to declare a read-only variable VAR with value 100 and then print it.
Bash Scripting
[1] VAR=100 [2] $VAR
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of 'echo' to display the value.
Using 'export' which does not make the variable read-only.
✗ Incorrect
Use 'readonly' to declare the variable and 'echo' to print its value.
5fill in blank
hardFill all three blanks to declare a read-only variable NAME with value 'Alice', print it, and then try to change it (which should fail).
Bash Scripting
[1] NAME="Alice" [2] $NAME NAME=[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' instead of 'echo' to display the value.
Trying to change the readonly variable without unsetting it first.
✗ Incorrect
Declare NAME as readonly, print it with echo, then attempt to assign a new value "Bob" which will fail.