从bash脚本循环遍历多个文件扩展名 [英] Loop over multiple file extensions from bash script
本文介绍了从bash脚本循环遍历多个文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Linux终端中使用的bash脚本,该脚本应类似于:
I need a bash script for use in the Linux terminal which should go something like:
#!/bin/bash
for textgrid_file in ./*.TextGrid and for wav_file in ./*.wav
do
praat --run pitch.praat "$textgrid_file" "$wav_file" >> output.txt
done
即我需要遍历具有扩展名.textgrid
和.wav
的文件对,因为在我的Praat脚本pitch.praat
中,我有两个参数要传递.如何通过bash脚本实现它?
I.e. I need to iterate through pairs of files with extensions .textgrid
and .wav
because in my Praat script pitch.praat
I have two arguments to pass. How can I implement it via bash scripting?
推荐答案
您可以使用数组支持来遍历第一个glob模式并使用数组中的第二个文件:
You can use an array support to iterate over first glob pattern and use 2nd file from array:
waves=(*.wav)
k=0
for textgrid_file in *.TextGrid; do
praat --run pitch.praat "$textgrid_file" "${waves[k++]}" >> output.txt
done
这篇关于从bash脚本循环遍历多个文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文