Article 51ZF6 [SOLVED] Shell script not able to parse a string under if statement

[SOLVED] Shell script not able to parse a string under if statement

by
296.saurabh
from LinuxQuestions.org on (#51ZF6)
I have a simple script in which I am trying to find if make some_target exists or not. In case it does not exist then print a statement and exit 1.

#!/bin/bash
set +ex
output=$(make -n some_target 2>&1 | head -1)
if [ "$output" == *"No rule to make target"* ]; then
echo "Target is not Present"
exit 1
else
echo "foo"
fi

but it is throwing an error and going into else loop

test.sh: 4: [: make: *** No rule to make target 'some_target'. Stop.: unexpected operator
foolatest?d=yIl2AUoC8zA latest?i=p3G9muegA_k:iczLCi3piWQ:F7zBnMy latest?i=p3G9muegA_k:iczLCi3piWQ:V_sGLiP latest?d=qj6IDK7rITs latest?i=p3G9muegA_k:iczLCi3piWQ:gIN9vFwp3G9muegA_k
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments