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]" ] 


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

There's always arithmetic syntax error.

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


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

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

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]" ]]
  • NOTE == only works with [[ – Alexej Magura Oct 25 '16 at 15:41
  • 1
    @AlexejMagura That is mentioned in the answer. From answer: == (inside [[) – heemayl Oct 25 '16 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.