gpt4 book ai didi

linux - 在子 shell 中运行的脚本不运行与调用脚本相同的 shell

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:08 24 4
gpt4 key购买 nike

我有一个使用 nohup 调用 shell B 的 shell A。

shell A:

echo "\r\n OS1 : $BASH \r\n"
echo "\r\n OS2 : $SHELL \r\n"

$scriptB="B.sh"

(
nohup sh $scriptB $* >> test.log 2>&1
echo process finalized
exit
)

shell B:

echo "\r\n OS1 : $BASH \r\n"
echo "\r\n OS2 : $SHELL \r\n"

在 shell A 中我得到了回显结果:

OS1 : /usr/bin/bash
OS2 : /usr/bin/sh

在 shell B 中,我得到了回显结果:

OS1 : 
OS2 : /usr/bin/sh

为什么bash在call中被清空了?如何在下标中继续使用 bash?

这导致我在某些命令中出现语法错误,这些命令在 bash 中可用但在 sh 中不可用

最佳答案

试试这个:

文件A.sh

echo "\r\n OS1 : $BASH \r\n"
echo "\r\n OS2 : $SHELL \r\n"

(
nohup sh ./B.sh $* >> test.log 2>&1
echo process finalized
exit
)

并保持文件 B 不变,它为两者打印出相同的输出。

关于linux - 在子 shell 中运行的脚本不运行与调用脚本相同的 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41630151/

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