2013-04-22 138 views
0

我有这个简单的bash脚本: 我运行ns模拟器在每个文件传递参数最后一个参数是一些文本字符串搜索。Bash脚本:不需要的输出

#!/bin/bash 

nsloc="/home/ashish/ns-allinone-2.35/ns-2.35/ns" 
temp="temp12345ashish.temp" 

j=1 

for file in "[email protected]" 
do 
     if [ $j -lt $# ] 
     then 
       let j=$j+1 

       `$nsloc $file > $temp 2>&1` 

       if grep -l ${BASH_ARGV[0]} $temp 
       then 
         echo "$file Successful" 

       fi 

     fi 
done 

我预计:

file1.tcl Successful 

我越来越:

temp12345ashish.temp 
    file1.tcl Successful 

当我在终端上运行模拟器命令自己,我没有得到其输出指向的文件名。

我没有从第一行输出得到打印。 请解释一下。

在此先感谢。

回答

3

man grep,看看具体的-l选项的解释。

在您的脚本(上面)中,您使用的是-l,所以grep会告诉您(按照指示)匹配发生的文件名。

如果您不想看到文件名,请不要使用-l或使用-q。例如:

grep -ql ${BASH_ARGV[0]} $temp 
0

只是沉默的grep:

if grep -l ${BASH_ARGV[0]} $temp &> /dev/null