今晚看《Linux Command Line and Shell Scrpiting Bible 2nd editon》说到了 internal field separator(内部字段分隔符),然后我研究了一下,因为我有点疑惑,百度了一下,最终解决了
1 #!/bin/bash 2 file="/home/tcstory/desktop/states" 3 ifs=$IFS 4 #IFS.OLD=$IFS 在这里 我不能用xxx.xxx来接收值,但是书上就是这么写的,可能是终端的类型不同,我这个不是ubuntu默认的模拟终端器 5 IFS=$' ' 6 if [ -f $file ];then 7 for state in `cat $file` 8 do 9 echo "Visit beautiful $state" 10 done 11 else 12 echo The file does not exist.! 13 fi 14 IFS=:!$'