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)
echo "$output"
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
make: *** No rule to make target 'some_target'. Stop.
test.sh: 5: [: make: *** No rule to make target 'some_target'. Stop.: unexpected operato
foo
testing for an exact match which there is not. That's why theelsebranch is taken. Try comparing to the exact message.*will be literal if quoted.