Introduction
Double quotes let you use variables inside text so the shell replaces them with their values.
echo "Hello, $USER!"name="Alice" echo "Hello, $name!"
count=5 echo "You have $count new messages."
path="/home/user folder" echo "Path is: $path"
#!/bin/bash user="Bob" message="Welcome to the system" echo "$message, $user!"
"$name"?name is replaced by its value inside the quotes. -> Option Auser with a greeting using double quotes in bash?$user to expand inside the string.$user is literal. echo Hello, $user! lacks quotes, which can cause word splitting. echo "Hello, 'user'!" quotes 'user' literally inside double quotes.name="Alice" echo "Hello, $name!" echo 'Hello, $name!'
$name to "Alice", so output is "Hello, Alice!".file="my file.txt" echo $file ls "$file"
echo $file splits "my file.txt" into two words, printing as two separate arguments.echo "$file" preserves the space and prints the full filename correctly.echo "$file". -> Option Acount inside double quotes, but only if count is not empty. Which is the best way to write this?[ "$count" ] safely tests if count is non-empty, even if it contains spaces or is unset.echo expands $count properly inside the string.Pass the test and this pattern moves unknown