-5

What does the following from https://unix.stackexchange.com/a/154290/674 mean?

In general, in shells other than zsh, $PATH outside double quotes breaks when the value contains spaces or other special characters, but in an assignment, it's safe

Could you give some example? Thanks.

Tim
  • 101,790

1 Answers1

1

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

michael
  • 842