Challenge - 5 Problems
Bash Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Bash script?
Consider the following Bash script. What will it print when run?
Bash Scripting
VAR=Hello
echo "$VAR"Attempts:
2 left
💡 Hint
Remember, in Bash, variable assignment must not have spaces around the equals sign.
✗ Incorrect
The variable VAR is assigned the value Hello without spaces around =. Then echo prints the value of VAR, which is Hello.
💻 Command Output
intermediate2:00remaining
What error does this Bash script produce?
What happens when you run this script?
MYVAR = World
echo "$MYVAR"
Bash Scripting
MYVAR = World
echo "$MYVAR"Attempts:
2 left
💡 Hint
Check if spaces around = are allowed in Bash variable assignment.
✗ Incorrect
Bash treats 'MYVAR' as a command because of the spaces around =, so it tries to run a command named MYVAR and fails.
📝 Syntax
advanced2:00remaining
Which option correctly assigns a variable in Bash?
Choose the correct way to assign the value '42' to the variable NUMBER in Bash.
Attempts:
2 left
💡 Hint
No spaces are allowed around the equals sign in Bash variable assignment.
✗ Incorrect
Only option D has no spaces around =, which is the correct syntax for Bash variable assignment.
🚀 Application
advanced2:00remaining
What is the value of VAR after running this script?
Given this script, what is the value of VAR printed?
VAR=foo
VAR=bar
VAR=baz
echo "$VAR"
Bash Scripting
VAR=foo
VAR=bar
VAR=baz
echo "$VAR"Attempts:
2 left
💡 Hint
The last assignment to a variable overwrites previous ones.
✗ Incorrect
The variable VAR is assigned three times. The last assignment sets it to 'baz', which is printed.
🔧 Debug
expert3:00remaining
Why does this Bash script fail to assign the variable correctly?
Examine the script below and identify why the variable assignment does not work as expected.
MYVAR=Hello World
echo "$MYVAR"
Bash Scripting
MYVAR=Hello World
echo "$MYVAR"Attempts:
2 left
💡 Hint
In Bash, spaces in variable assignment need special handling.
✗ Incorrect
Without quotes, Bash treats 'World' as a separate command, causing an error. To assign a string with spaces, quotes are needed.