Search code examples
bashfor-loopwildcardglob

how to prevent bash from returning wildcard when variable is in double quotes?


Here the second variable is not a found directory but a search pattern. How to prevent this behavior ?

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

result:

mytestdir001
mytestdir???

Solution

  • You've misinterpreted the problem. The issue is that you have quoted the wildcards when you shouldn't have.

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