通过符号链接访问时 bash 似乎忽略 BASH_ENV
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用 bash 手册页:
请注意,当作为交互式 shell 运行时,现代
sh
使用$ENV
的方式类似于bash
使用$BASH_ENV
代码>. bash 也模仿了这种行为。Quoting bash manpage:
Note that when run as interactive shell, modern
sh
uses$ENV
in a manner similar to the waybash
uses$BASH_ENV
. This behavior is mimicked by bash as well.当
bash
被作为sh
调用时,它故意表现不同,并禁用许多bash
扩展。其中一项变化似乎是它不再读取
$BASH_ENV
指定的文件。您可以通过将文件(暂时)变成常规文件并看到与常规文件相同的行为来证明这与符号链接无关。When
bash
is invoked assh
, it intentionally behaves differently, and disables a number ofbash
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.