Linux Shell 中如何定义整型变量?

我想实现这一功能:
例如脚本名是 show.sh,参数是5的时候执行这5句:
cat /var/log/http_test.000.log | tail -2
cat /var/log/http_test.001.log | tail -2
cat /var/log/http_test.002.log | tail -2
cat /var/log/http_test.003.log | tail -2
cat /var/log/http_test.004.log | tail -2

参数是3的时候执行这3句:
cat /var/log/http_test.000.log | tail -2
cat /var/log/http_test.001.log | tail -2
cat /var/log/http_test.002.log | tail -2
……
依此类推。
参数的范围是1~100。由于文件名由前缀0来补齐3位数,所以要根据循环变量的范围来执行不同分支。
我写的脚本如下:
#!/bin/bash

if [ $# -ne 1 ]; then
echo "./show.sh <num>"
fi

declare -i show_num=$1
declare -i tmp

for ((tmp=0; tmp<show_num; tmp=tmp+1))
do
if [ tmp -lt 10 ]; then
cat /var/log/http_test.00$tmp.log | tail -2
else
cat /var/log/http_test.0$tmp.log | tail -2
fi
done

运行到“if [ tmp -lt 10 ]; then”这句时出现:
./show.sh: line 12: [: tmp: integer expression expected
错误。
请问该如何修改?

if [ $tmp -lt 10 ] 变量前面加$号
温馨提示:答案为网友推荐,仅供参考