假设你有〜/ mytool目录,软链接到/usr/local / mytool.然后cd mytool将当前目录保留为〜/ mytool,这可能导致脚本行为不正确.有没有办法避免这种行为?
通过一些谷歌搜索,我看到你可以实现如下:
cd $1 ; cd `pwd -P`
没有切换到’cd’吗?环境变量?
如果在bash中键入set -P,则所有命令(如cd,pwd)都将遵循物理路径.否则,您可以使用cd -P和pwd -P临时更改默认行为.
原文链接:https://www.f2er.com/bash/385642.html从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文件中,例如.