I am trying to compare strings in bash. I have already found the answer on how to do this on https://stackoverflow.com/a/3/2208/ . In the script I am trying, I am using the code provided by Adam in the indicated question:
#!/bin/bash string='My string'; if [[ "$string" == *My* ]] then echo "It there!"; fi needle='ys' if [[ "$string" == *"$needle"* ]]; then echo "haystack '$string' contains needle '$needle'" fi
I also tried the approach from ubuntuforums , which you can find in the 2nd post
if [[ $var =~ regexp ]]; then
In both cases, I get an error message:
[[: not found
What am I doing wrong?
user1581900 Sep 01 '12 at 19:23 2012-09-01 19:23
source share