为什么~/.bashrc中$0的值为bash?
echo "`pwd`/$0 loaded"
我预计/home/thinker3/.bashrc已加载 但结果:
thinker3@ubuntu:~$ source .bashrc
/home/thinker3/bash loaded
感谢 Michael Hoffman,我的问题得到了解决,我补充了
echo $BASH_SOURCE loaded
到 ~/.bashrc 和/etc/profile,然后:
/home/thinker3/.bashrc loaded
thinker3@ubuntu:~/addons$ su - root
Password:
/etc/profile loaded
root@ubuntu:~#
最佳答案
正如 Uroc327 指出的,.bashrc
是有源的,因此 $0
只是被调用进程的名称(可能是 bash
,就像您从命令行回显了 $0
)。加载 .bashrc
时,$BASH_SOURCE
的值将包含文件的位置。
关于bash - .bashrc 中 $0 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17381197/