0
0
Bash Scriptingscripting~20 mins

Variable assignment (no spaces around =) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bash Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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"
Aecho $VAR
BVAR=Hello
CHello
DSyntax error
Attempts:
2 left
💡 Hint
Remember, in Bash, variable assignment must not have spaces around the equals sign.
💻 Command Output
intermediate
2: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"
Abash: MYVAR: command not found
BMYVAR = World
CWorld
DSyntax error
Attempts:
2 left
💡 Hint
Check if spaces around = are allowed in Bash variable assignment.
📝 Syntax
advanced
2:00remaining
Which option correctly assigns a variable in Bash?
Choose the correct way to assign the value '42' to the variable NUMBER in Bash.
ANUMBER = 42
BNUMBER =42
CNUMBER= 42
DNUMBER=42
Attempts:
2 left
💡 Hint
No spaces are allowed around the equals sign in Bash variable assignment.
🚀 Application
advanced
2: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"
Afoo
Bbaz
Cbar
DSyntax error
Attempts:
2 left
💡 Hint
The last assignment to a variable overwrites previous ones.
🔧 Debug
expert
3: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"
AThe variable is assigned only 'Hello', and 'World' is treated as a command causing an error.
BThe variable MYVAR is assigned the full string 'Hello World' correctly.
CThe script prints 'Hello World' without errors.
DThe variable assignment syntax is correct and works as intended.
Attempts:
2 left
💡 Hint
In Bash, spaces in variable assignment need special handling.