gpt4 book ai didi

linux - 如何在禁用 tty 时输出子 shell

转载 作者:太空宇宙 更新时间:2023-11-04 12:35:40 26 4
gpt4 key购买 nike

  • 我正在通过禁用 tty 的自动化工具运行我的 shell。

父类.sh

echo "parent shell"
./child.sh

子.sh

echo child shell
  • 当我在终端控制台上执行 parent.sh 时它会输出我

    parent shell
    child shell
  • 但是当我通过禁用 tty 的自动化工具执行时。它只输出我:

    parent shell
  • 有人可以解释为什么会出现这种行为吗?除了将子 shell 输出重定向到另一个文件并打印它们之外,我该如何实现。

最佳答案

我找到了答案。我们必须使用 bash 调用子 shell。
即,bash child.sh

这背后的原因是,当我们调用子 shell 时,它会在新 shell 中执行,而我的自动化工具仅在父 shell 中打印输出。当我使用 bash 调用时,它会在父 shell 中执行子 shell。

因为我使用了 bash shell,所以我正在使用 bash 执行。对于其他 shell,您需要使用相应的 shell 关键字调用子脚本。

关于linux - 如何在禁用 tty 时输出子 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41930361/

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