Reputation: 2590
I knows the ${para:[start]:[length]}
and $@
notation but I'm unable to find out how ${var: -1}
evaluates to the last argument.
Upvotes: 3
Views: 51
Reputation: 799062
From the bash(1)
man page:
If parameter is @ ... an offset of -1 evaluates to the last positional parameter.
Upvotes: 3
Reputation: 47119
Consider it as length - 1
which will resolve in the last character in $var
. Same goes for ${var:(-2)}
, ...:
var='hello'
printf "%s\n" "${var:(-1)}" # o
printf "%s\n" "${var:(-2)}" # lo
printf "%s\n" "${var:(-3)}" # llo
Upvotes: 5