首页 > 解决方案 > $str == *"somestring"* 与使用正则表达式

问题描述

我目前正在运行以下 bash 脚本。但是,我不确定这种方法是否完全是一种好方法。我正在尝试test在以下目录路径中查找子字符串。最好的方法是什么?正则表达式?使用以下示例寻找一些指导

for str in "/directory/manifest" "directory/test/configs" "directory/test/secrets" "directory/main" "directory/bin"; do
    if [[ $str == *"test"* ]];then
        echo $str
    fi
done

标签: bash

解决方案


推荐阅读