为什么下面的文件读取器和注释行检查会跳过空行?
while read line; do
if [ ! ${line:0:1} == "#" ]; then # leave out comments
function_call $line
fi
done < list_items.txt发布于 2018-12-27 23:16:07
跳过空行的行为是由不带引号的bash变量引起的,比较字符串时请始终使用引号:
while read line; do
if [ ! "${line:0:1}" == "#" ]; then # leave out comments
function_call "${line}"
fi
done < list_items.txt上面的代码将处理空行。
https://stackoverflow.com/questions/53945071
复制相似问题