Perl,python和R如何从外部输入参数

2019-08-17  本文已影响0人  gtt儿_生物信息学习

分别用Perl,python和R从外部输入hello_world.
其中hello_world为从外部输入的参数。

Perl

perl的脚本如下:

print "$ARGV[0]\n";

提交命令:

perl test.pl hello_world

输出结果:

hello_world

python

python的脚本如下:

import sys
print (sys.argv[1])

提交命令:

python test.py hello_world

输出结果:

hello_world

R

R的脚本如下:

args = commandArgs(trailingOnly=TRUE)
print (args[1])

提交命令:

Rscript test.r hello_world

输出结果:

hello_world

需要注意的是Perl默认第一个输入的参数为ARGV[0],从0开始。而python和R都是从1开始。

上一篇 下一篇

猜你喜欢

热点阅读