[英]Bash script: Looping through multiple file extensions in folder, ignoring file extensions that don't exist
[英]looping over a few file extensions in bash
我在一个文件夹中有一个文件列表,我只想处理其中的几个。 该文件夹包含有file.qc、file.qc.gz、file.qc.stat、file.qc.count等文件。
我想在 bash 中编写一个循环,它只会打开 file.qc 和 file.qc.gz,而忽略其他文件扩展名(例如 qc.stats 或 qc.count)
只需在循环中指定多个 glob:
#!/bin/bash
# Gracefully cases where there are no matches
shopt -s nullglob
for f in *.qc *.qc.gz
do
echo "Found: $f"
done
你也可以把它写成*.qc{,.gz}
,它扩展成同样的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.