Bash-If条件内参数的不同值
从文件$2输入:1->2Bash-If条件内参数的不同值,bash,if-statement,Bash,If Statement,从文件$2输入:1->2 while read -a line; do if (( ${line[2]} > linesNumber )); then echo "Graph does not match known sites4" exit fi done < "$2" 什么是行数?即使你把$linesNumber,它从哪里来 如果要跟踪行号,则需要设置行号并将其递增。这是我的示例程序和数据。它是从你的例子中得到启发的,但并不完全符合你的要求。但是,它向您
while read -a line; do
if (( ${line[2]} > linesNumber )); then
echo "Graph does not match known sites4"
exit
fi
done < "$2"
什么是
行数
?即使你把$linesNumber
,它从哪里来
如果要跟踪行号,则需要设置行号并将其递增。这是我的示例程序和数据。它是从你的例子中得到启发的,但并不完全符合你的要求。但是,它向您展示了如何设置跟踪行号的变量,如何增加行号,以及如何在if
语句中使用行号:
foo.txt:
该方案:
你的意思是让
$$linesNumber
的${line[2]}
的值不变:-)
你的错误在其他地方!我不认为echo命令做了您认为它做的事情——反引号意味着它将接受${line[2]}
的值,作为命令执行,并回显其输出。
echo `${line[2]}`
2
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