#!/bin/bash
txt="This is a text"
substr="text"
if [[ $txt == *$substr* ]]
then
echo "String [$txt] contains substring [$substr]"
else
echo "String [$txt] doesn't contains substring [$substr]"
fi
Variable txt is a string which should (or not) contains string from variable substr.
Output:
$ ./sub.sh
String [This is a text] contains substring [text]
Change variable substr:
substr="t1xt"
Output:
$ ./sub.sh
String [This is a text] doesn't contains substring [t1xt]
No comments:
Post a Comment