#!/bin/bash
STR='foobar/group/dog/name'
SUB=["group/dog/name", "group/dog2/name"]
if [[ "$STR" contains *"$SUB"* ]]; then
echo "It's there and print out the matching substring: group/dog/name"
fi
#!/bin/bash
str='foobar/group/dog/name'
subs=('group/dog/name' 'group/dog2/name')
for sub in "${subs[@]}"; do
if [[ $str = *"$sub"* ]]; then
echo "$sub"
fi
done
2条答案
按热度按时间dgsult0t1#
这也许就是你想做的
hwazgwia2#
使用针阵列构建正则表达式并使用
grep
如果堆栈是数组,则可以将其连接以进行测试