gpt4 book ai didi

linux - Bash 脚本 : Unwanted Output

转载 作者:太空宇宙 更新时间:2023-11-04 09:03:18 25 4
gpt4 key购买 nike

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

#!/bin/bash

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

j=1

for file in "$@"
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

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

我不知道第一行输出的打印位置。请解释一下。

提前致谢。

最佳答案

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

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

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

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

关于linux - Bash 脚本 : Unwanted Output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16155591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com