答:在子shell执行,那么变量的值总是不能如愿以偿的改变,示例如下: #!/bin/sh var="jello" cat "jello.txt" | while read line do var=${line} done echo "var=${var}" 看见示例中的管道了吗!这是个陷阱,会导致while在子shell 中执行,以至于var的值并没有被改变 解决方法: #!/bin/sh while read line do var=${li…
一.IFS 介绍 Shell 脚本中有个变量叫 IFS(Internal Field Seprator) ,内部域分隔符.完整定义是The shell uses the value stored in IFS, which is the space, tab, and newline characters by default, to delimit words for the read and set commands, when parsing output from command sub…