IFS is the Input Field Separator, which means the string read will be split based on the characters in IFS. On a command line, IFS is normally any whitespace characters, that's why the command line splits at spaces. the canonical way to read one line…
用bash脚本读文件的方法有很多.请看第一部分,我使用了while循环及其后的管道命令(|)(cat $FILE | while read line; do … ),并在循环当中递增 i 的值,最后,我得到了非我所想的 i .主要的原因是,管道命令会发起子shell来读取文件,而任何在(子shell的)while循环中的操作(例如 i ++),都会随着子shell的结束而丢失. 而第二种,也是最坏的一种,其最明显的错误就是在读文件的过程中使用了for循环(for fileline in $(ca…
转自:http://blog.csdn.net/guodongxiaren/article/details/43341769 总第8篇 本系列(玩转Bash脚本)更多文章,请访问:http://blog.csdn.net/column/details/wanbash.html 和其他语言一样Bash的循环结构中也有while语句. 基本结构 while 条件 do 循环体 done 和for语句一样,它的循环体同样是do…done结构.我们可以把while语句再折叠一下 while 条件;d…