Variables in simple assignments (e.g. a=$b
) are by definition (i.e., POSIX specification), not usually necessary to quote -- in most cases, anyway. That is because in these assignments, the "string-splitting" and "globbing" (i.e., white-space and wildcards like *
) are not expanded.
In other cases, other than assignments, the variable (echo $b
) is expanded -- including whitespaces (string-splitting) -- and hence should be quoted (echo "$b"
), to prevent problems, in case it contains whitespace. E.g., consider if I'm not using echo
as an example, but instead another command: cmd $b
is going to receive multiple args if there are spaces in $b
, but cmd "$b"
will receive one argument, even if it has spaces.
See also: https://stackoverflow.com/questions/3958681/quoting-vs-not-quoting-the-variable-on-the-rhs-of-a-variable-assignment