简体   繁体   中英

looping over a few file extensions in bash

I have a list of files in a folder and I want to just work on a few of them. The folder contains files with file.qc, file.qc.gz file.qc.stat file.qc.count and so on.

I want to write a loop in bash that will open only the file.qc and file.qc.gz, while ignoring other file extensions (such as qc.stats or qc.count)

Just specify multiple globs in your loop:

#!/bin/bash

# Gracefully cases where there are no matches
shopt -s nullglob

for f in *.qc *.qc.gz
do
  echo "Found: $f"
done

You can also write this shorter as *.qc{,.gz} , which expands to the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM