${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:t
only keeps the last segment.$myPath:t2
preserves 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 2
myPath="/home/user/work/file.csv" echo $myPath:t
1
file.csv
- Print basename and parent directory of a path
- Output:
1 2
myPath="/home/user/work/file.csv" echo ${myPath:t2}
1
work/file.csv
BashSupport Pro ist eine Zsh IDE mit Unterstützung für $varName:t - probieren Sie es jetzt aus!