${name:t<number>}: Path tail
Shortens a file path by only preserving the tail.
If <number> appears within a parameter expansion (e.g. ${name:t<number>}) and is greater than zero,
then this number of trailing segments is preserved instead of just the last segment.
$myPath:tonly keeps the last segment.$myPath:t2preserves the last two segments of the path, e.g. the filename and the immediate parent directory.
Modifier :h is the opposite and evaluates to the head of the path.
Links
Examples
- Print basename of a path
- Output:
1 2myPath="/home/user/work/file.csv" echo $myPath:t1file.csv - Print basename and parent directory of a path
- Output:
1 2myPath="/home/user/work/file.csv" echo ${myPath:t2}1work/file.csv
BashSupport Pro ist eine Zsh IDE mit Unterstützung für $varName:t - probieren Sie es jetzt aus!