jeudi 2 novembre 2017

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. The scenario is that $output has multiple "ORA-" strings in separate lines, but it doesnot have "INVALID_OBJECTS" string. So first part is true, but second part becomes

"" -gt 0

which fails with

sh: [: missing `]'

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

Aucun commentaire:

Enregistrer un commentaire