“ / path / file / ..”如何与POSIX兼容?

问题描述 投票:6回答:1

我想将当前目录更改为Shell脚本更改为包含特定常规文件的目录。我发现以下技巧在mkshbusybox sh中起作用:

path=/path/to/regular/file
cd $path/.. 

但不是在GNU Bash中:

bash: cd: /path/to/regular/file/..: Not a directory

此技巧是否与posix不兼容,或者Bash过于腐?

shell posix cd
1个回答
2
投票

该标准的最新版本不允许这样做。 POSIX.1-2017 cd spec.明确指出,如果点号之前的路径名组件不是目录,则cd应认为是错误。

来自cd

cd § DESCRIPTION - step 8.b
© www.soinside.com 2019 - 2024. All rights reserved.