加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 防止’cd’记住遍历的符号链接

发布时间:2020-12-15 18:34:29 所属栏目:安全 来源:网络整理
导读:假设你有?/ mytool目录,软链接到/usr/local / mytool.然后cd mytool将当前目录保留为?/ mytool,这可能导致脚本行为不正确.有没有办法避免这种行为? 通过一些谷歌搜索,我看到你可以实现如下: cd $1 ; cd `pwd -P` 没有切换到’cd’吗?环境变量? 如果在bas
假设你有?/ mytool目录,软链接到/usr/local / mytool.然后cd mytool将当前目录保留为?/ mytool,这可能导致脚本行为不正确.有没有办法避免这种行为?

通过一些谷歌搜索,我看到你可以实现如下:

cd $1 ; cd `pwd -P`

没有切换到’cd’吗?环境变量?

如果在bash中键入set -P,则所有命令(如cd,pwd)都将遵循物理路径.否则,您可以使用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文件中,例如.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读