biocyberman
biocyberman

Reputation: 5915

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

I am reading some zsh scripts and found this syntax ${PWD:A}. I know what $PWD is and the bash variable substitution syntax (largely thanks to this excellent tutorial). Despite of that, I haven't found any docs that explain about the ${variable:flag} syntax for zsh.

Upvotes: 1

Views: 1989

Answers (1)

Adaephon
Adaephon

Reputation: 18389

${PWD:A} returns the symlink-free absolute path of $PWD. It does so by:

  • prepending the current directory
  • resolving any .. and .
  • resolving symbolic links, if the system has the realpath system call - which modern systems do.

As $PWD already is the absolute path of the current directory and does not contain .. or . elements (at least it really should not), ${PWD:A} only has to resolve any symbolic links.


The ${name:flag} syntax allows the use of History Expansion Modifiers on parameters.

It actually is explained in the section Parameter Expansion of the ZSH Manual (see also man zshexpn). Unfortunately it is just a single sentence in the text and not listed with the other ${nameXXXXX} expansions:

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.

A list of the available modifiers can be found in the subsection Modifiers under History Expansion. In the case of 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).

Upvotes: 2

Related Questions