[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
foo


#!/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
foo