gpt4 book ai didi

linux - 如何在不运行 source 命令的情况下将子 shell 的执行行打印到主 shell?

转载 作者:太空宇宙 更新时间:2023-11-04 04:39:32 30 4
gpt4 key购买 nike

假设我有一个名为 foo.sh 的可执行 shell 脚本。里面有一个简单的 echo “Hello World”。根据我的理解,当我通过 ./foo.sh 运行它时,会调用一个子 shell 来执行 echo“Hello World”行。

那么,为什么我会在主 shell/终端中看到 echo 命令的输出?我认为您必须执行“source ./foo.sh”而不是简单的“./foo.sh”才能查看当前 shell 中的输出。

你们谁能帮忙澄清一下吗?

最佳答案

标准输出是继承的。引用自Bash Reference Manual :

Command Execution Environment

When a simple command other than a builtin or shell function is to beexecuted, it is invoked in a separate execution environment thatconsists of the following. Unless otherwise noted, the values areinherited from the shell.

  • the shell’s open files, plus any modifications and additions specified by redirections to the command
  • ...

关于linux - 如何在不运行 source 命令的情况下将子 shell 的执行行打印到主 shell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55596112/

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