我有以下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进行更改。现在,我确实知道输出的文件扩展名。但是outputs1和outputs2具有相同的文件扩展名。你知道吗
对于这种情况的最佳实践是从stdin读取脚本并将其写入stdout。在这种情况下,通过管道将它们连接起来变得非常容易,如下所示:
在您的情况下,您可以编写这样的脚本:
虽然不太理想,但它可以满足你的需要。它将读取input1.tsv,并写入outputs3。你知道吗
您的问题不是这样说的,但是假设您可以使用
o
标志指定输出文件:/dev/stdin
和/dev/stdout
是神奇的unix文件,分别写入进程stdin
和stdout
。你知道吗相关问题 更多 >
编程相关推荐