假设你有目录〜/ mytool,它们可以连接到/ usr / local / mytool。 然后, cd mytool
将当前目录保留为〜/ mytool,这可能会导致脚本的行为不正确。 有没有办法避免这种行为?
用一些Googlesearch,我看到你可以做到这一点如下:
cd $1 ; cd `pwd -P`
有没有切换到“CD”? 环境variables?
如果在bash中键入set -P
命令,例如cd,则pwd将遵循物理path。 否则,您可以使用cd -P
和pwd -P
临时更改默认行为。
从bash的手册:
-P If set, the shell does not follow symbolic links when executing commands such as cd that change the cur- rent working directory. It uses the physical directory structure instead. By default, bash follows the logical chain of directories when performing commands which change the current directory.
例如,为了使这个永久的,把它放在你的~/.bashrc
文件中。
“cd”是大部分炮弹内置的。 在bash中,你可以通过添加来获得你想要的行为
set -P
在启动脚本(.bashrc,说)。
在Ubuntu / Debian(不知道BSD), cd -P symlink
把我放在解决的符号链接path。 (与pwd -P相同的行为)
testing使用:
mkdir a ln -sab cd -P b && pwd