I am working on scripting and using bash shell for execution. Following are two different variations that I am trying to execute. but its not working not on execution there is error on console for double bracket in if condition.
#!/bin/bash
STR='GNU/Linux is an operating system'
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]
then
echo "It's there."
else
echo "Not It's there."
fi
if [[ $STR =~ $SUB ]]; then
echo found
else
echo not found
fi
I took the reference of this example from https://linuxize.com/post/how-to-check-if-string-contains-substring-in-bash/ . now not sure why its not working. But in my project, following syntax is working fine. Here I was checking for equality which works fine but in above example I want to verify contains.
if [ $1= "test" ]
then
test=true
elif [ $1= "dev ]
then
dev=true
fi
Bash Version
OS
can someone help me ?



test.sh, marked it as executable, and then ran./test.sh. The output wasIt's therefollowed byfound. Could you give more details about your environment and exactly how you are running code? Did you copy and paste the exact code that you are running into this question?$SHELLdoesn't necessarily reflect the shell you're actually running at the time; it's just your preferred one.