簡體   English   中英

在 bash 中循環幾個文件擴展名

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM