【发布时间】:2019-02-17 07:22:14
【问题描述】:
我正在编写一个 shell 脚本来读取文件中的空格数。
我正在使用以下模板逐行阅读
while read l
do
done <filename
但它在读取一行时将多个空格转换为一个空格。
【问题讨论】:
-
while IFS= read l... -
您遗漏了重要部分。你如何使用这个变量?
-
while IFS= read -r l do echo $l echo $l>temp wc -L temp|cat >length len=
cut -d " " -f 1 lengthecho $len done -
你必须引用你的变量。
echo "$l"否则当你echo时会发生分词...