我有两个shell脚本,a.sh和b.sh。
我如何从shell脚本a.sh调用b.sh ?
我有两个shell脚本,a.sh和b.sh。
我如何从shell脚本a.sh调用b.sh ?
当前回答
使用引号。
$ ./script-that-consumes-argument.sh `sh script-that-produces-argument.sh`
然后获取生产者脚本的输出,作为消费者脚本的参数。
其他回答
取决于。 短暂的…… 如果你想在当前控制台加载变量并执行,你可以在你的代码中使用myshell .sh源代码。例子:
#!/bin/bash
set -x
echo "This is an example of run another INTO this session."
source my_lib_of_variables_and_functions.sh
echo "The function internal_function() is defined into my lib."
returned_value=internal_function()
echo $this_is_an_internal_variable
set +x
如果你只想执行一个文件,你唯一感兴趣的是结果,你可以这样做:
#!/bin/bash
set -x
./executing_only.sh
bash i_can_execute_this_way_too.sh
bash or_this_way.sh
set +x
pathToShell="/home/praveen/"
chmod a+x $pathToShell"myShell.sh"
sh $pathToShell"myShell.sh"
使用引号。
$ ./script-that-consumes-argument.sh `sh script-that-produces-argument.sh`
然后获取生产者脚本的输出,作为消费者脚本的参数。
假设新文件为“/home/satya/app/app_specific_env”,文件内容如下
#!bin/bash
export FAV_NUMBER="2211"
将该文件引用附加到~/。bashrc文件(
source /home/satya/app/app_specific_env
当您重新启动机器或重新登录时,尝试在终端中echo $FAV_NUMBER。它将输出该值。
以防万一,如果您想立即看到效果,请使用source ~/。在命令行中使用Bashrc。
首先,你必须包含你调用的文件:
#!/bin/bash
. includes/included_file.sh
然后像这样调用函数:
#!/bin/bash
my_called_function