分页: 1 / 1

shell 脚本小问题求解!

发表于 : 2012-02-06 22:46
ubuntu_2012
今天在shell 练习脚本的时候发现:

代码: 全选

#!/bin/bash
if [ $# -ne 2 ];
then
        echo "Usage:$0 string file";
        exit 1;
fi
grep $1 $2;

if [ $? -ne 0 ];
then
        echo "Not Found \"$1\" in $2";
        exit 1;
fi
echo "Found \"$1\" in $2"
我输入: ./process.sh Usage process.sh
为什么输出为这个:
echo "Usage:$0 string file";
Found "Usage" in process.sh ?? 难道是Ubuntu的问题?

Re: shell 脚本小问题求解!

发表于 : 2012-02-06 23:10
枫叶饭团
echo "Usage:$0 string file";
这货怎么会输出,我也没明白

Re: shell 脚本小问题求解!

发表于 : 2012-02-07 0:27
fnan
那是grep的输出。

Re: shell 脚本小问题求解!

发表于 : 2012-02-07 0:38
枫叶饭团
fnan 写了:那是grep的输出。
:em05 :em05 :em25

Re: shell 脚本小问题求解!

发表于 : 2012-02-07 8:43
aerofox
一点问题也没有,第一行是 grep 的输出,第二行是最后一条echo语句的输出。