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.

marked as duplicate by muru, ilkkachu bash Jun 8 '18 at 4:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.