${PWD:A} 是什么意思?

what is the meaning of ${PWD:A}?

我正在阅读一些 zsh 脚本并发现了这种语法 ${PWD:A}。我知道 $PWD 是什么以及 bash 变量替换语法(很大程度上要感谢 this excellent tutorial)。尽管如此,我还没有找到任何文档来解释 zsh.

的 ${variable:flag} 语法

${PWD:A} returns $PWD 的无符号链接绝对路径。它通过以下方式实现:

  • 前置当前目录
  • 解决任何 ...
  • 解析符号链接,如果系统有 realpath 系统调用——现代系统有。

As $PWD already 当前目录的绝对路径,不包含...元素(至少它真的不应该),${PWD:A} 只需要解析任何符号链接。


${name:flag}语法允许在参数上使用历史扩展修饰符

它实际上 Parameter Expansion of the ZSH Manual 部分中解释的(另请参阅 man zshexpn)。不幸的是,它只是文本中的一个句子,没有与其他 ${nameXXXXX} 扩展一起列出:

In addition to the following operations, the colon modifiers described in Modifiers in History Expansion can be applied: for example, ${i:s/foo/bar/} performs string substitution on the expansion of parameter $i.

可以在小节 Modifiers under History Expansion 中找到可用修饰符的列表。在A的情况下:

a

Turn a file name into an absolute path: prepends the current directory, if necessary, and resolves any use of .. and . in the path. Note that the transformation takes place even if the file or any intervening directories do not exist.

A

As a, but also resolve use of symbolic links where possible. Note that resolution of .. occurs before resolution of symbolic links. This call is equivalent to a unless your system has the realpath system call (modern systems do).