I noticed that
IFS=;
read v1 v2 <<< "hey;hello"
stores the entire string "hey;hello" in $v1
while
IFS=";"
read v1 v2 <<< "hey;hello"
does the expected action, which is storing "hey" in $v1 and "hello" in $v2
why is that? from what I understand, there's no need to put quotes when assigning a string, as long as there's no whitespace involved
CodePudding user response:
from what I understand, there's no need to put quotes when assigning a string, as long as there's no whitespace involved
The right-hand side of an assignment only has globbing and string-splitting disabled; otherwise, it's syntactically similar to any other context.
Consequently, it's not just whitespace that needs to be quoted -- you still need quotes when your string contains characters that would be parsed as some kind of syntax (other than the two types of expansion that's squelched inside that context) whose effect you want to avoid.
;
is a command separator; thus, it terminates the current command when unquoted. Thus, you need to quote or escape it here.