- 论坛徽章:
- 0
|
跳出循环,变量值消失. SOS
下面是整个代码: 是一个将input 传给一程序, 然后和一个output文件比较. 列出不一样的test case.
INDEX=1
LAST_INDEX=1
CASENO=1
LINENO=1
if [ $# -ne 3 ]
then
echo "Usage: tester executable_file_name input_file_name output_file_name."
exit 0
fi
if [ ! -x $1 ]
then
echo "$1 is not an executable file."
fi
if [ ! -r $2 ]
then
echo "$2 is not a readable file."
fi
if [ ! -r $3 ]
then
echo "$3 is not a readable file."
fi
TOTALLINE=`wc -l $3 | sed "s/ $3$//" | sed "s/^ //"`
readonly TOTALLINE
for TOKEN in `cat $2`
do
EXP="$EXP $TOKEN"
if [ $TOKEN = "=" -o $TOKEN = "==" ]
then
if [ ! -w /tmp/tmp2$$ ]
then
echo "=========" > /tmp/tmp2$$
else
echo "=========" >> /tmp/tmp2$$
fi
echo $EXP | $1 >> /tmp/tmp2$$
echo "RC=$?" >>/tmp/tmp2$$
#read one output of test case and put it in /tmp/tmp$$ file. Then cut
#these lines.
while [ 1 ]
do
LINE=`sed -n -e "$LINENO p" $3`
echo "$LINE"
LINENO=`expr $LINENO + 1`
export LINENO
echo "line number = $LINENO"
if [ ! -w /tmp/tmp1$$ ]
then
echo $LINE >/tmp/tmp1$$
else
echo $LINE >>/tmp/tmp1$$
fi
THREECHAR=`echo $LINE | cut -c1-3`
#echo $THREECHAR
if [ $THREECHAR = "RC=" ]
then
break
fi
done < $3
unset EXP
if [ "`diff /tmp/tmp1$$ /tmp/tmp2$$`" ]
then
echo $CASENO
fi
CASENO=`expr $CASENO + 1`
/usr/bin/rm /tmp/tmp1$$ /tmp/tmp2$$
fi
done
调用格式为: tester program_name input_file output_file |
|