0
0
Bash Scriptingscripting~10 mins

Read-only variables (readonly) 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 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'
Avar1
Bmy_var
CMY_VAR
Dreadonly
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'readonly' as the variable name.
Using lowercase variable names when uppercase is expected.
2fill in blank
medium

Complete 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'
AMY_VAR
B$MY_VAR
CMY_VAR$
D${MY_VAR}
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.
3fill in blank
hard

Fix 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'
Aunset MY_VAR
Breadonly MY_VAR
Cexport MY_VAR
DMY_VAR
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.
4fill in blank
hard

Fill 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'
Areadonly
Becho
Cprint
Dexport
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.
5fill in blank
hard

Fill 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'
Areadonly
Becho
C"Bob"
Dprint
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.