tags:

views:

53

answers:

2

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 ?

+5  A: 

The second will handle whitespace properly instead of folding it into the first character of $IFS. Use it when you want whitespace handled properly.

Ignacio Vazquez-Abrams
+2  A: 

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.

dogbane