为什么以下文件阅读器和带注释的行检查跳过了空行?
while read line; do
if [ ! ${line:0:1} == "#" ]; then # leave out comments
function_call $line
fi
done < list_items.txt
答案 0 :(得分:1)
跳过空行的行为是由不引用bash变量引起的,在比较字符串时始终引用:
while read line; do
if [ ! "${line:0:1}" == "#" ]; then # leave out comments
function_call "${line}"
fi
done < list_items.txt
以上将处理空行。