【发布时间】:2019-02-07 11:33:35
【问题描述】:
我有一个包含 Perl 脚本和 R 脚本的 Shell 脚本。
我的 Shell 脚本 R.sh:-
#!/bin/bash
./R.pl #calling Perl script
`perl -lane 'print $F[0]' /media/data/abc.cnv > /media/data/abc1.txt`;
#Shell script
Rscript R.r #calling R script
这是我的 R.pl(头):-
`export path=$PATH:/media/exe_folder/bin`;
print "Enter the path to your input file:";
$base_dir ="/media/exe_folder";
chomp($CEL_dir = <STDIN>);
opendir (DIR, "$CEL_dir") or die "Couldn't open directory $CEL_dir";
$cel_files = "$CEL_dir"."/cel_files.txt";
open(CEL,">$cel_files")|| die "cannot open $file to write";
print CEL "cel_files\n";
for ( grep { /^[\w\d]/ } readdir DIR ){
print CEL "$CEL_dir"."/$_\n";
}close (CEL);
Perl 脚本的输出是 Shell 脚本的输入,Shell 的输出是 R 脚本的输入。
我想通过提供输入文件名和输出文件名来运行 Shell 脚本:-
./R.sh home/folder/inputfile.txt home/folder2/output.txt
如果文件夹包含许多文件,那么它只需要用户定义文件并处理它。 有没有办法做到这一点?
【问题讨论】:
-
您可以将文件名作为参数传递给脚本,也可以通过环境变量传递。
-
您的意思是
perl perl_script.pl <parameters for perl> ¦ sh shell_script.sh <parameters for shell> ¦ r r_script.r <parameters for r script>并且您想将该命令行放入另一个shell 脚本中? (假设 perl 和 shell 脚本写入stdout并且 shell 和 R 脚本从stdin读取) -
@StefanBecker 我只想为 shell 脚本传递一次参数。 ./R.sh 。 R.sh 首先调用一个 Perl 脚本,然后调用一个 R 脚本。
-
请提供minimal reproducible example,在您的情况下至少提供
R.sh的内容 -
@StefanBecker 查看编辑