Recall & Review
beginner
Why should there be no spaces around the
= sign in bash variable assignment?In bash, spaces around
= are not allowed because bash treats spaces as separators. Spaces would cause bash to misinterpret the command, leading to errors.Click to reveal answer
beginner
What is the correct way to assign the value
hello to a variable named greeting in bash?The correct way is
greeting=hello. No spaces should be before or after the = sign.Click to reveal answer
beginner
What happens if you write
greeting = hello in bash?Bash will try to run a command named
greeting with arguments = and hello, causing an error because greeting is not a command.Click to reveal answer
intermediate
How do you assign a value with spaces to a variable in bash?
You put the value in quotes without spaces around
=. For example: message="hello world".Click to reveal answer
beginner
Is this valid in bash?
name= JohnNo, it is invalid because there is a space after
=. The correct form is name=John.Click to reveal answer
Which of these is the correct way to assign the value 10 to a variable x in bash?
✗ Incorrect
In bash, no spaces are allowed around the equals sign during variable assignment.
What will happen if you run
var =value in bash?✗ Incorrect
Bash treats 'var' as a command and '=value' as its argument because of the spaces.
How do you assign the string 'hello world' to a variable message in bash?
✗ Incorrect
The value with spaces must be quoted and no spaces around '='.
Which is NOT a valid variable assignment in bash?
✗ Incorrect
Spaces around '=' are not allowed in bash variable assignments.
Why does bash require no spaces around '=' in variable assignment?
✗ Incorrect
Bash uses spaces to separate commands and arguments, so spaces around '=' break the assignment.
Explain why spaces are not allowed around the equals sign in bash variable assignment.
Think about how bash reads commands and arguments.
You got /3 concepts.
Show how to correctly assign a string with spaces to a variable in bash.
Remember how to handle strings with spaces.
You got /3 concepts.