gpt4 book ai didi

linux - 如何修复第 42 行 : [: too many arguments in Linux?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:45:27 24 4
gpt4 key购买 nike

我有 1 个以 #!/bin/ksh 开头的脚本

这是创建第 42 行的代码片段:[: too many arguments

if  [ -f "$Log_dir/output.rej" ] && 
[ grep -Hne "fails to validate" $Log_dir/output.rej >/dev/null ]

它扩展为 (set -xv)

+ '[' -f /export/home/xxxx/xsdlog/output.rej ']'
+ '[' grep -Hne 'fails to validate' /export/home/xxxx/xsdlog/output.rej ']'
TEST_VALIDATE.sh: line 42: [: too many arguments

我试过了

if  [ -f $Log_dir/output.rej ] &&
[ grep -Hne "fails to validate" $Log_dir/output.rej >/dev/null ]

不带引号(")。结果相同。

如何修复此错误?

最佳答案

停止尝试使用 [ 命令执行另一个命令。

if ... && grep ...

例子:

if  [ -f "$Log_dir/output.rej" ] && 
grep -Hne "fails to validate" $Log_dir/output.rej >/dev/null
then
...
fi

关于linux - 如何修复第 42 行 : [: too many arguments in Linux?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22109225/

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