我正在尝试查看一个字符串是否是 shell 脚本 (#!bin/sh) 中另一个字符串的一部分。
我现在的代码是:
#!/bin/sh
#Test scriptje to test string comparison!
testFoo () {
t1=$1
t2=$2
echo "t1: $t1 t2: $t2"
if [ $t1 == "*$t2*" ]; then
echo "$t1 and $t2 are equal"
fi
}
testFoo "bla1" "bla"
我正在寻找的结果是我想知道“bla1”中何时存在“bla”。
谢谢和亲切的问候,
更新:我已经尝试过这里描述的“包含”函数:你如何判断一个字符串是否在 Unix shell 脚本中包含另一个字符串?
但是,它们似乎与普通的 shell 脚本(bin/sh)不兼容......
帮助?