bash - 从 bash 脚本循环多个文件扩展名

标签 bash

我需要一个在 Linux 终端中使用的 bash 脚本,其内容应类似于:

#!/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 脚本实现它?

最佳答案

您可以使用数组支持来迭代第一个 glob 模式并使用数组中的第二个文件:

waves=(*.wav)

k=0
for textgrid_file in *.TextGrid; do
    praat --run pitch.praat "$textgrid_file" "${waves[k++]}" >> output.txt
done

关于bash - 从 bash 脚本循环多个文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49103942/

相关文章:

linux - 什么都没有改变时的rsync inode差异

linux - 从文件列表中选择文件

Bash for循环与命令的多行输出

windows - 将基于 Windows 斜杠 (/) 的参数从 bash 脚本传递给程序

linux - 一个文件输入到脚本中的两个程序

bash - 我的 WHILE-DO 循环出了什么问题,或者为什么我的脚本找不到我在盘子上提供的文件?

bash - 留在 bash 脚本结束后更改的目录中

Bash - 获取文件名的前 3 个字母

bash - 如何将 'reset' bash 恢复为出厂设置 - MacOS Sierra

java - 从守护进程线程调用的 scp 进程失败并缺少/dev/tty