以单个bash脚本运行多个工具

时间:2015-09-22 13:35:10

标签: c++ r bash terminal

我正在孤立地做不同的程序。假设一个命令行arg用于C ++工具,另一个用于R。但是首先我运行C ++ app的命令行参数,这将给出一个结果文件。只有这样我才能为R app运行另一个命令行,这需要从C ++应用程序生成文件。

我可能有许多不同的数据需要处理。有没有办法让bash脚本允许循环不同的工具(C ++,R,任何其他)?所以我只是坐下来不要手动编写许多命令行参数?

我想去睡觉,而耗时的循环却在我的电脑里发出噪音。

1 个答案:

答案 0 :(得分:1)

以某种定义的顺序运行多个不同的程序是(系统)脚本语言的基本思想,如bash:

## run those three programms in sequence
first argument
second parameter
third
# same as
first argument; second parameter; third

你可以做很多奇特的事情,比如重定向输入和输出流:

grep secret secrets.file | grep -V strong | sort > result.file
# pipe | feeds everything from the standard output
# of the programm on the left into
# the standard input of the one on the right

这还包括条件,当然还有循环:

while IFS= read -r -d '' file; do
  preprocess "$file"
  some_work | generate "$file.output"
done < <(find ./data -type f -name 'source*' -print0)

正如您所看到的,bash本身就是一种编程语言,有一些奇怪的语法恕我直言。