[英]shell scripting multiple conditions in single if condition
In the code below, in /bin/sh, why is second condition of -o evaluated when first condition is satisfied. 在下面的代码中,在/ bin / sh中,当满足第一个条件时为什么评估-o的第二个条件。 The scenario is that $output has multiple "ORA-" strings in separate lines, but it doesnot have "INVALID_OBJECTS" string.
方案是$ output在单独的行中有多个“ ORA-”字符串,但没有“ INVALID_OBJECTS”字符串。 So first part is true, but second part becomes
所以第一部分是正确的,但是第二部分变成
"" -gt 0
“” -gt 0
which fails with 失败了
sh: [: missing `]'
sh:[:缺少`]'
if [ "`echo "$output" | grep ORA-`" -o "`echo "$output" | awk '/INVALID_OBJECTS/{getline;getline;print $0}' | sed 's/\s//g'`" -gt 0 ]; then
echo -e "\n*** ERROR: ***\n"
fi
UPDATE: The $output holds stdout of pl-sql block. 更新:$ output保存pl-sql块的stdout。 The end-user had entered Ctrl+C during execution of the pl-sql block, which resulted in loss of connection to SQL* Plus.
最终用户在执行pl-sql块期间输入了Ctrl + C,这导致与SQL * Plus的连接断开。 So the stdout ended up having multiple "ORA-nnnnn" errors.
因此,标准输出最终出现多个“ ORA-nnnnn”错误。 If there was no loss of connection, I would have got the following lines in $output which is checked in left side of the -o check.
如果没有连接丢失,我将在$ output中得到以下几行,这些行在-o检查的左侧进行检查。
INVALID_OBJECTS
_ _ _ _ _ _ _ _ _ _
3
Well, let's simplify your expression first a bit, by removing unnecessary quotes. 好吧,让我们先删除多余的引号来简化您的表达式。 The test command basically boils down to:
测试命令基本上可以归结为:
[ `echo $output | grep ORA-` -o `echo $output | awk '/INVALID_OBJECTS/{getline;getline;print $0}' | sed 's/\s//g'` ]
So you have basically zero or more words (depending on what the grep yields) on the left of the -o
, followed by zero or one word (depending on what awk yields) to the right of the -o
. 所以,你有基本为零或多个字(取决于grep的收益率是什么)在左侧
-o
,其次是零或一个字(这取决于AWK收益率)的右侧-o
。
Now I have no idea WHAT you want to achieve here, but you can see from this analysis, that your command does not make sense. 现在我不知道您要在这里实现什么,但是从此分析可以看出,您的命令没有任何意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.