使用NOHUP调用带有参数的Shell脚本方法

发布于 2025-02-10 01:30:10 字数 350 浏览 1 评论 0原文

/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2025-02-17 01:30:10

如果通过参数,则必须以某种方式使用它们。从技术上讲,一种可能性是将您的脚本写入您的脚本,就像

start(){
 first="$1";
 echo "arg is $first"
}

"$@"

最后一行一样 - 在您的情况下 - 扩展到start arg1,因此调用您的函数。 但是,这样做是有风险的:由于您的脚本的第一个参数(即开始)被视为要执行的命令,因此脚本的用户可以注入任何通过参数代码。这是一个严重的安全漏洞。

我至少会以某种方式验证第一个参数,或完全重新设计您的脚本。例如,目前尚不清楚为什么要定义一个函数,如果脚本不做其他任何事情,请调用此功能。

If you pass parameters, you have to use them somehow. One possibility is technically do write your script as

start(){
 first="$1";
 echo "arg is $first"
}

"$@"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文