I am trying to see if a string is part of another string in shell script (#!bin/sh).
The code i have now is:
#!/bin/sh
#Test scriptje to test string
In bash you can write (note the asterisks are outside the quotes)
if [[ $t1 == *"$t2"* ]]; then
echo "$t1 and $t2 are equal"
fi
For /bin/sh, the =
operator is only for equality not for pattern matching. You can use case
though
case "$t1" in
*"$t2"*) echo t1 contains t2 ;;
*) echo t1 does not contain t2 ;;
esac
If you're specifically targetting linux, I would assume the presence of /bin/bash.