1

I want to check the result of a job and execute an action on FAILED.

First: I grep the last word of the line in my application logfile (for the recent processed file ($processedfilename)):

check1=$(grep "$processedfilename" "$logfile" | grep "anotherword" | \
    grep "FAILED" | tail -1 | awk '{print $NF}')

This results in [FAILED].

Now I want to check on the result

if [ $check1 -eq "[[FAILED]" ] 
then

or

if [ $check1 -eq "\[FAILED]" ] 
then

There's always arithmetic syntax error.

What's the correct syntax to check on [FAILED]?

0

2 Answers 2

3

You should always double quote variables. And you need = for string equals. So:

if [ "$check1" = "[FAILED]" ]; then
3

You are doing an arithmetic comparison by using -eq leading to the error, you need to do string comparison by using = (or == inside [[), and for that using quotes is enough:

[ "$check1" = "[[FAILED]" ]
[[ "$check1" = "[[FAILED]" ]]
2
  • NOTE == only works with [[ Commented Oct 25, 2016 at 15:41
  • 1
    @AlexejMagura That is mentioned in the answer. From answer: == (inside [[)
    – heemayl
    Commented Oct 25, 2016 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .