假设我有以下Bash脚本:
while read SCRIPT_SOURCE_LINE; do echo "$SCRIPT_SOURCE_LINE" done
我注意到,对于没有换行符的文件末尾,这将有效地跳过最后一行。
When read reaches end-of-file instead
of end-of-line,it does read in the
data and assign it to the variables,
but it exits with a non-zero status.
If your loop is constructed “while
read ;do stuff ;doneSo instead of testing the read exit
status directly,test a flag,and have
the read command set that flag from
within the loop body. That way
regardless of reads exit status,the
entire loop body runs,because read
was just one of the list of commands
in the loop like any other,not a
deciding factor of if the loop will
get run at all.06001