在大多数符合 POSIX 标准的 shell 中,如bash
. ksh
, dash
, mksh
, pdksh
, 当变量赋值发生时,在赋值的 RHS 中不执行字段拆分和文件名扩展(如果 shell 支持,则扩展括号):
$ IFS=/
$ a=1/2
# Field splitting and filename expansion turned off here
$ b=$a
$ IFS=
$ printf '%s\n' $b
1/2
Run Code Online (Sandbox Code Playgroud)
一些 shell 的文档(bash,ksh)提到了这一点,但POSIX 文档没有。
我可以在大多数符合 POSIX 的 shell 中看到这种行为,所以我想知道它是否可移植,因为 POSIX 文档没有指定它?