【发布时间】:2020-11-17 18:39:11
【问题描述】:
我正在尝试确定子字符串(文件名)是否存在于包含许多文件路径的大字符串中。这是我的代码,它不起作用(打印“不包含”)。我尝试与=~ 比较,不同的引号用法。似乎没有任何效果。您在我的代码中发现问题了吗?
#!/bin/bash
text="/path/to/some/file1-2-3.json /another/path/to/file4-5-6.json"
my_file="file1-2-3.json"
if [[ *"$my_file"* == "$text" ]]; then
echo "Contain"
else
echo "Does not contain"
fi
【问题讨论】:
标签: string bash string-comparison