小编Ale*_*T82的帖子

Linux Shell脚本 - 与通配符的字符串比较

我试图看看一个字符串是否是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"
Run Code Online (Sandbox Code Playgroud)

我正在寻找的结果是,我想知道"bla1"中存在"bla"的时间.

谢谢和亲切的问候,

更新:我已经尝试了这里描述的"包含"函数:如何判断字符串是否包含Unix shell脚本中的另一个字符串?

以及String中的语法包含在bash中

但是,它们似乎与普通的shell脚本(bin/sh)不兼容......

救命?

linux string shell sh

17
推荐指数
1
解决办法
4万
查看次数

标签 统计

linux ×1

sh ×1

shell ×1

string ×1