登录shell使用什么方法读取/etc/profile?

登录shell使用什么方法读取/etc/profile?

登录shell使用什么方法来读取/etc/profile

答案1

它是有来源的。执行和采购之间的区别解释如下这个帖子。这里的重要区别是,sourceing 会导致源文件中的命令在当前 shell 中运行。这意味着文件中定义的任何变量现在都可以在 shell 中使用。为了说明差异,请尝试以下操作:

$ cat foo        ## a simple file with a variable definition
var="hello"
$ chmod +x foo   ## make file executable
$ ./foo          ## execute
$ echo "$var"    ## var is not set in the parent shell

$ . foo          ## source
$ echo "$var"    ## var is now set in the parent shell
hello

因此,由于/etc/profile需要能够影响读取它的 shell,所以它是来源并且没有被执行。

答案2

shell 获取这些文件。

在子进程中执行此操作意味着 shell 不会在其自己的环境中设置变量等,因为它们将在子进程的环境中设置(这些是单独的)。子进程不能将其环境传递回父进程。

也可以看看:如何使子 shell 中的变量在父 shell 中可用

相关内容