【发布时间】:2017-06-16 14:02:35
【问题描述】:
我有以下 Perl 脚本(尽管这适用于 Python 和其他脚本语言):script1.pl、script2.pl、script3.pl
这些脚本的编写方式,用户使用输入标志执行它们,输出是保存的文件。
perl script1.pl --i input1.tsv ## this outputs the file `outputs1`
perl script2.pl --i outputs1 ## this outputs the file `outputs2`
perl script3.pl --i outputs2 ## this outputs the file `final_output`
(对于 Python 爱好者,这是python script1.py)
现在,我想创建一个可执行的 bash 脚本,它允许用户简单地使用 input1 并获得输出作为返回 final_output。
这就是我只用一个 perl 脚本execute.sh 来做到这一点的方法:
#!/bin/sh
source ~/.bash_profile
FLAG1="--i=$1"
perl script1.pl $FLAG1
可以在命令行上运行execute.sh input1.tsv
对于我的三个脚本示例,我如何将中间输出通过管道传输到中间脚本以创建一个 execute.sh 脚本,例如outputs1 变成script2.pl,然后outputs2 变成scripts3.pl,等等?
有没有办法让我在不重写 perl/python 脚本的情况下做到这一点?
编辑:附加信息:问题是我实际上不知道输出是什么。文件名根据原始的 inputs1.tsv 更改。现在,我确实知道输出的文件扩展名。但是输出 1 和输出 2 具有相同的文件扩展名。
【问题讨论】:
-
通过使用正确的文件名调用脚本,与手动执行相同,除了它在脚本中。不需要魔法。
-
脚本是否需要特定的输入/输出文件?通常,您只需将它们以
< input1.tsv perl script1.pl | perl script2.pl | perl script3.pl > outputs2的形式通过管道传输(当然,还要编写脚本,这样就可以了) -
如果脚本总是输出到硬连线的文件名,除了改变脚本别无他法。
-
您能否解释一下为什么在 bash 脚本中连续运行三个命令不起作用?
-
@ShanZhengYang 这将是问题中的好信息。
标签: python linux bash perl shell