I'm using Ubuntu system shell, not bash, and I found the regular way can not work:
#!/bin/sh string='My string'; if [[ $string =~ .*My.* ]] then echo "It's there!" fi
error [[: not found!
What can I do to solve this problem?
Using grep for such a simple pattern can be considered wasteful. Avoid that unnecessary fork, by using the Sh built-in Glob-matching engine (NOTE: This does not support regex):
case "$value" in *XXX*) echo OK ;; *) echo fail ;; esac
It is POSIX compliant. Bash have simplified syntax for this:
if [[ "$value" == *XXX* ]]; then :; fi
and even regex:
[[ abcd =~ b.*d ]] && echo ok
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With