bash - 使用不同的输入文件运行脚本

标签 bash ubuntu groovy terminal

过去两周我一直在使用 groovy。我有一个脚本,我通常会这样运行:

    groovy script input

其中 input 是输入文件的名称。但是,现在我想对大约 100 个这些文件的整个目录重复相同的操作 - 有没有办法在一个命令中运行它,而不是一个接一个?

最佳答案

当然,使用 shell 循环:

for file in *; do groovy script "$file" > file.out; done

这将遍历当前目录中的所有文件(和目录)。要使其递归,这意味着它还将在子目录中查找,请使用:
shopt -s globstar
for file in **/*; do groovy script "$file" > file.out; done

最后,要避免使用目录(如果有),请使用:
for file in *; do [ -f "$file" ] && groovy script "$file" > file.out; done

关于bash - 使用不同的输入文件运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088989/

相关文章:

bash 脚本 : How to test list membership

bash 在循环时删除我的文件 "~$ ./program > file.dat"(gnuplot)

node.js - bower 命令不返回任何内容

java - 动态 GString 创建不符合我的预期

Groovy 属性定义

bash - 检查用户是否存在

linux - 以文字模式从另一个脚本编写 bash 脚本

python - 尝试在虚拟环境中安装 flask 时出错

linux - 无法为 Linux 构建和安装 Geary

java - 如何在不同的gradle任务之间共享参数