Concept Flow - String variables
Declare variable
Assign string value
Use variable
Print or manipulate string
End
This flow shows how a string variable is declared, assigned, used, and printed in bash scripting.
name="Alice" echo "Hello, $name!"
| Step | Action | Variable 'name' | Output |
|---|---|---|---|
| 1 | Declare and assign name="Alice" | Alice | |
| 2 | Print greeting with echo | Alice | Hello, Alice! |
| 3 | End of script | Alice |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| name | undefined | Alice | Alice | Alice |
String variables in bash: - Assign with: name="value" - Use with $name - Use double quotes to preserve spaces and expand variables - Print with echo "Hello, $name!" - Without $, variable name prints literally
Hello to a variable named greeting in bash?name in bash?$name correctly. echo name prints the literal word 'name'. The other options use invalid symbols.name="Alice" echo "Hello, $name!"
name is assigned the string "Alice".$name is replaced by its value "Alice".message = "Hi there" echo $message
message = "Hi there" has spaces around =, causing a syntax error.fullname and then print it. Which script correctly does this?echo $fullname to print the stored string value.Pass the test and this pattern moves unknown