来自文件 $2 的输入:1 -> 2
while read -a line; do
if (( ${line[2]} > linesNumber )); then
echo "Graph does not match known sites4"
exit
fi
done < "$2"
出于某种原因,if
条件内部的值${line[2])
不是2
,但如果我在外部打印值if
:
echo `${line[2]}`
2
来自文件 $2 的输入:1 -> 2
while read -a line; do
if (( ${line[2]} > linesNumber )); then
echo "Graph does not match known sites4"
exit
fi
done < "$2"
出于某种原因,if
条件内部的值${line[2])
不是2
,但如果我在外部打印值if
:
echo `${line[2]}`
2
是什么linesNumber
?即使你放$linesNumber
,它是从哪里来的?
如果您正在跟踪行号,则需要设置它并增加它。这是我的示例程序和数据。它受到您的示例的启发,但并不完全符合您的要求。但是,它向您展示了如何设置跟踪行号的变量、如何增加它以及如何在if
语句中使用它:
this 1
that 2
foo 4
barf 4
flux 5
lineNum=0
while read -a line
do
((lineNum++))
if (( ${line[1]} > $lineNum ))
then
echo "Line Number Too High!"
fi
echo "Verb = ${line[0]} Number = ${line[1]}"
done < foo.txt
Verb = this Number = 1
Verb = that Number = 2
Line Number Too High!
Verb = foo Number = 4
Verb = barf Number = 4
Verb = flux Number = 5