gpt4 book ai didi

linux - 从主 bash 脚本启动另一个 bash 脚本

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:07 25 4
gpt4 key购买 nike

我有一个 bash 脚本,我需要从中启动另一个带有 source 的脚本。这工作正常,但我还需要传递第二个脚本参数。

例子:

source /usr/local/scripts/parallel.sh test --gnu

所以我需要用一个名为 test 的给定数据源文件启动 parallel.sh,我还需要分配一个参数 --gnu 最后。但是它不识别文件和参数。

最佳答案

source command可能不是您要找的东西。

When a script is run using source it runs within the existing shell, any variables created or modified by the script will remain available after the script completes. In contrast if the script is run just as filename, then a separate subshell (with a completely separate set of variables) would be spawned to run the script.

因此,除非您需要访问 parallel.sh 中的变量或函数,否则直接调用它即可:

/usr/local/scripts/parallel.sh test --gnu

只要脚本是可执行的 (chmod +x/usr/local/scripts/parallel.sh) 并设置为使用您传递的选项 ($1 将包含“test”,$2 将包含“--gnu”),它应该可以正常工作。

关于linux - 从主 bash 脚本启动另一个 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35892217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com