${(D)…}
: Reverse filename expansion
(D)
assumes that the scalar or array variable contains file paths.
It replaces the prefix of these paths with placeholders like ~
and escapes the remainder of the path.
Links
Examples
- Print shortened, escaped filepath
- Output:
1 2 3 4 5
path="$HOME/temp/file with spaces.txt" echo "File path: ${(D)path}" paths=("$HOME/file1.txt" "$HOME/file2.txt") echo "File paths: " ${(D)paths}
1 2
File path: ~/temp/file\ with\ spaces.txt File paths: ~/file1.txt ~/file2.txt
BashSupport Pro is a Zsh IDE with support for ${(D)…} – try it now!