${(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.

Examples

Print shortened, escaped filepath
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}
Output:
1
2
File path: ~/temp/file\ with\ spaces.txt
File paths:  ~/file1.txt ~/file2.txt
BashSupport Pro ist eine Zsh IDE mit Unterstützung für ${(D)…} - probieren Sie es jetzt aus!
© 2020–2024 Joachim Ansorg
Impressum
Datenschutz
Rechtliches