我有 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/