Recall & Review
beginner
What is a string variable in bash scripting?
A string variable in bash scripting is a named storage that holds a sequence of characters, like words or sentences, which you can use and change in your script.
Click to reveal answer
beginner
How do you assign a string value to a variable in bash?
You assign a string to a variable by writing the variable name, an equal sign, and the string without spaces around the equal sign. For example:
name="Alice".Click to reveal answer
beginner
How do you access the value of a string variable in bash?
You access the value by putting a dollar sign before the variable name, like
$name. This tells the script to use the stored string.Click to reveal answer
beginner
What happens if you put spaces around the equal sign when assigning a string variable in bash?
Bash will give an error because spaces are not allowed around the equal sign when assigning variables. It expects
var=value without spaces.Click to reveal answer
beginner
How can you include spaces inside a string variable in bash?
You put the string inside quotes, like
greeting="Hello world". Quotes keep the spaces as part of the string.Click to reveal answer
How do you assign the string 'hello' to a variable named msg in bash?
✗ Incorrect
In bash, assignment must have no spaces around '=', and strings with spaces or special characters should be in quotes. So msg="hello" is correct.
What does $name mean in a bash script?
✗ Incorrect
The dollar sign before a variable name tells bash to use the value stored in that variable.
Which of these is a valid string variable assignment in bash?
✗ Incorrect
You must not have spaces around '=', and strings with spaces must be quoted. So greeting="Hello World" is valid.
What will happen if you run: name =John in bash?
✗ Incorrect
Bash does not allow spaces around '=' in variable assignment, so this causes a syntax error.
How do you include spaces inside a string variable in bash?
✗ Incorrect
Putting the string inside quotes keeps spaces as part of the string value.
Explain how to create and use a string variable in bash scripting.
Think about how you store and then use a word or sentence in your script.
You got /3 concepts.
What common mistake should you avoid when assigning string variables in bash?
Remember how bash reads variable assignments carefully.
You got /3 concepts.