Tim*_*Tim 0 shell environment-variables
$ IFS=";"
$ read first second
i am;a_i b c
$ echo $first
i am
$ echo $second
a_i b c
$ echo $IFS
Run Code Online (Sandbox Code Playgroud)
read first second
是当前 shell 进程的子进程吗?如果是,为什么我们不需要export IFS=";"
?IFS
空的?我是否正确地认为第一秒是当前 shell 进程的子进程?如果是,为什么我们不需要 export IFS=";"?
不,read
是bash bultin 函数。这里没有创建子shell或子进程,所以我们不需要导出IFS
.
为什么 IFS 是空的?
因为你不使用双引号。你已经改变了价值IFS来;
,所以当你echo $IFS
,以后$IFS
扩展到;
,外壳执行字的分裂和通配符,以;
作为分隔符。所以什么都没有打印。
尝试:
$ IFS=";"
$ printf "%s\n" $IFS
$ printf "%s\n" "$IFS"
;
Run Code Online (Sandbox Code Playgroud)
笔记