Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用列表作为 for 循环的参数;但是使用双引号时,列表不会被理解为列表,而没有引号时,通配符会被评估为文件名。
A="a* b*" for ex in "$A"; do echo "$ex"; done for ex in $A; do echo "$ex"; done
第一个打印:
a* b*
后者打印:
a.txt b.txt
我想:
我怎样才能使这项工作?
您可以set -f禁用路径名扩展:
set -f
A="a* b*" ( set -f for ex in $A ; do echo "$ex" done )
使用数组:
A=("a*" "b*") for ex in "${A[@]}"; do echo "$ex" done