如何将参数从 QSub 传递到 Bash 脚本? [英] How to Pass Parameters from QSub to Bash Script?

查看:55
本文介绍了如何将参数从 QSub 传递到 Bash 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 QSub 将变量传递给 Bash 脚本时遇到问题.

I'm having an issue passing variables to a Bash script using QSub.

假设我有一个名为 example 的 Bash 脚本.示例格式如下:

Assume I have a Bash script named example. The format of example is the following:

#!/bin/bash
# (assume other variables have been set)

echo $1 $2 $3 $4

因此,在终端上执行bash example.sh 这是一个测试"(我使用的是 Ubuntu 12.04.3 LTS,如果有帮助的话)会产生输出这是一个测试".

So, executing "bash example.sh this is a test" on Terminal (I am using Ubuntu 12.04.3 LTS, if that helps) produces the output "this is a test".

但是,当我输入qsub -v this,is,a,test example.sh"时,没有输出.我检查了 QSub 生成的输出文件,但找不到这是一个测试"这一行.

However, when I enter "qsub -v this,is,a,test example.sh", I get no output. I checked the output file that QSub produces, but the line "this is a test" is nowhere to be found.

任何帮助将不胜感激.

谢谢.

推荐答案

使用 PBSPro 或 SGE,参数可以简单地放在脚本名称之后,这样看起来很直观.

Using PBSPro or SGE, arguments can simply be placed after the script name as may seem intuitive.

qsub example.sh hello world

在 Torque 中,可以使用 -F 选项提交命令行参数.您的 example.sh 将如下所示:

In Torque, command line arguments can be submitted using the -F option. Your example.sh will look something like this:

#!/bin/bashecho "$1 $2"

你的命令如下:

qsub -F "hello world" example.sh

或者,可以使用带有逗号分隔的变量列表的 -v 设置环境变量.

Alternatively, environment variables can be set using -v with a comma-separated list of variables.

#!/bin/bashecho "$FOO $BAR"

你的命令如下:

qsub -v FOO="hello",BAR="world" example.sh

(这可能更好地表述为对@William Hay 的回答的评论,但我没有这样做的声誉.)

(This may be better phrased as a comment on @William Hay's answer, but I don't have the reputation to do so.)

这篇关于如何将参数从 QSub 传递到 Bash 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆