4

In most POSIX compliant shell like bash. ksh, dash, mksh, pdksh, when variable assignment occur, field splitting and filename expansion (and brace expansion if the shell supports) are not performed in RHS of assignment:

$ IFS=/
$ a=1/2
# Field splitting and filename expansion turned off here
$ b=$a
$ IFS=
$ printf '%s\n' $b
1/2

Some shell's documentation (bash, ksh) mentioned about this, but POSIX documentation didn't.

I can see this behavior in most POSIX compliant shell, so I wonder is it portable since when POSIX documentation does not specify it?

6

Depends on where you look at. From Chapter 2, Section 9.1:

Each variable assignment shall be expanded for tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal prior to assigning the value.

I would assume that this list is exhaustive, and since field splitting is not mentioned, the lack of field splitting is POSIX-specified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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