我有很多具有这种模式的 pdf 文件: “TN_[0-9]{6}.pdf”,我需要检查文件是否具有此模式。我试过这个:
pattern = "TN_[0-9]{6}.pdf"
for file in *.pdf
do
if [[ "$file" =~ $pattern ]];
then
done
但它给了我
[[: not found
最佳答案
将 pattern = "TN_[0-9]{6}.pdf"
修改为 pattern="TN_[0-9]{6}.pdf"
。否则模式将被解释为命令。
关于regex - 匹配 bash 脚本中的单词模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51854807/