使用NOHUP调用带有参数的Shell脚本方法
/bin/scripts/first.ksh
#!/bin/bash
start(){
first="$1";
echo "arg is $first"
}
/bin/scripts/second.sh
#!/bin/bash
nohup sh /bin/scripts/first.ksh start arg1 > nohup_log 2>&1 &
未拾取参数。 在第二个脚本中通过参数的正确方法是什么?
/bin/scripts/first.ksh
#!/bin/bash
start(){
first="$1";
echo "arg is $first"
}
/bin/scripts/second.sh
#!/bin/bash
nohup sh /bin/scripts/first.ksh start arg1 > nohup_log 2>&1 &
The argument is not picked up.
What is the correct way to pass argument in the second script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果通过参数,则必须以某种方式使用它们。从技术上讲,一种可能性是将您的脚本写入您的脚本,就像
最后一行一样 - 在您的情况下 - 扩展到
start arg1
,因此调用您的函数。 但是,这样做是有风险的:由于您的脚本的第一个参数(即开始)被视为要执行的命令,因此脚本的用户可以注入任何通过参数代码。这是一个严重的安全漏洞。我至少会以某种方式验证第一个参数,或完全重新设计您的脚本。例如,目前尚不清楚为什么要定义一个函数,如果脚本不做其他任何事情,请调用此功能。
If you pass parameters, you have to use them somehow. One possibility is technically do write your script as
The last line would - in your case - expand to
start arg1
and therefore call your function. However it is risky to do this: Since the first parameter to your script (i.e. start) is treated as a command to be executed, the user of the script could inject any code via the parameter. This is a serious security hole.I would at least verify the first parameter somehow, or redesign your script completely. For instance, it is unclear why you define a function, if the script isn't doing anything else than calling this function.