通过符号链接访问时 bash 似乎忽略 BASH_ENV

发布于 2024-12-29 06:16:26 字数 668 浏览 2 评论 0原文

我正在 UNIX 环境中工作,其中 /bin 设置如下:

-rwxr-xr-x  1 root root 617144 Nov 19  2009 bash
lrwxrwxrwx  1 root root      4 Nov 23  2010 sh -> bash

在我的环境中,我已将 $BASH_ENV 设置为指向我的本地 .bashrc:

env | grep BASH
BASH_ENV=/home/users/atomicpirate/.bashrc

另外, .bashrc 的第一行是 echo BASHRC READ

我希望 /bin/sh 和 /bin/bash 的行为与此设置完全相同......但它们没有:

/bin/bash -c 'echo $BASH_ENV'
BASHRC READ
/home/users/atomicpirate/.bashrc

/bin/sh -c 'echo $BASH_ENV'
/home/users/atomicpirate/.bashrc

在第二种情况下,不读取 .bashrc 。知道为什么会这样吗?符号链接似乎破坏了 $BASH_ENV 的预期行为。

I'm working in a UNIX environment where /bin has been set up like this:

-rwxr-xr-x  1 root root 617144 Nov 19  2009 bash
lrwxrwxrwx  1 root root      4 Nov 23  2010 sh -> bash

In my environment I have set $BASH_ENV to point to my local .bashrc:

env | grep BASH
BASH_ENV=/home/users/atomicpirate/.bashrc

In addition, .bashrc has as its first line echo BASHRC READ.

I would expect /bin/sh and /bin/bash to behave exactly the same with this setup...but they don't:

/bin/bash -c 'echo $BASH_ENV'
BASHRC READ
/home/users/atomicpirate/.bashrc

/bin/sh -c 'echo $BASH_ENV'
/home/users/atomicpirate/.bashrc

In the second case, .bashrc is NOT read. Any idea why this would be the case? It seems like the symlink is breaking the expected behavior of $BASH_ENV.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的温暖 2025-01-05 06:16:26

引用 bash 手册页

如果使用名称 sh 调用 bash,它会尝试模仿
sh 的历史版本尽可能接近,
同时符合
POSIX 标准也是如此。

请注意,当作为交互式 shell 运行时,现代 sh 使用 $ENV 的方式类似于 bash 使用 $BASH_ENV代码>. bash 也模仿了这种行为。

Quoting bash manpage:

If bash is invoked with the name sh, it tries to mimic the startup behavior of
historical versions of sh as closely as possible,
while conforming to the
POSIX standard as well.

Note that when run as interactive shell, modern sh uses $ENV in a manner similar to the way bash uses $BASH_ENV. This behavior is mimicked by bash as well.

━╋う一瞬間旳綻放 2025-01-05 06:16:26

bash 被作为 sh 调用时,它故意表现不同,并禁用许多 bash 扩展。

其中一项变化似乎是它不再读取 $BASH_ENV 指定的文件。您可以通过将文件(暂时)变成常规文件并看到与常规文件相同的行为来证明这与符号链接无关。

When bash is invoked as sh, it intentionally behaves differently, and disables a number of bash extensions.

One of the changes, it appears, is that it no longer reads the file dictated by $BASH_ENV. You could prove that it is nothing to do with a symlink by making the file into a regular file (temporarily) and seeing the same behaviour with a regular file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文