In shell scripting what is the difference between these 2 when assigning one variable to another:
a=$b
and
a="$b"
and which one to use when ?
In shell scripting what is the difference between these 2 when assigning one variable to another:
a=$b
and
a="$b"
and which one to use when ?
The second will handle whitespace properly instead of folding it into the first character of $IFS
. Use it when you want whitespace handled properly.
Advanced Bash-Scripting Guide: Chapter 5: Quoting
When referencing a variable, it is generally advisable to enclose its name in double quotes. This prevents reinterpretation of all special characters within the quoted string. Use double quotes to prevent word splitting. An argument enclosed in double quotes presents itself as a single word, even if it contains whitespace separators.