【问题标题】:how to prevent bash from returning wildcard when variable is in double quotes?当变量在双引号中时如何防止bash返回通配符?
【发布时间】:2015-10-22 05:55:08
【问题描述】:

这里的第二个变量不是找到的目录,而是搜索模式。如何防止这种行为?

mkdir -p mytestdir001
for f in "mytestdir???"; do
  echo $f
  echo "$f"
done

结果:

mytestdir001
mytestdir???

【问题讨论】:

    标签: bash for-loop wildcard glob


    【解决方案1】:

    你误解了这个问题。问题是您在不应该引用的时候引用了通配符

    mkdir -p mytestdir001
    for f in "mytestdir"???; do
      echo $f
      echo "$f"
    done
    

    【讨论】:

      猜你喜欢
      • 2015-04-18
      • 2018-03-04
      • 2020-07-01
      • 1970-01-01
      • 2021-11-23
      • 2012-01-25
      • 1970-01-01
      • 2023-01-08
      • 1970-01-01
      相关资源
      最近更新 更多