Suppose I have the string 1:2:3:4:5 and I want to get its last field (5 in this case). How do I do that using Bash? I tried cut, but I
1:2:3:4:5
5
cut
If your last field is a single character, you could do this:
a="1:2:3:4:5" echo ${a: -1} echo ${a:(-1)}
Check string manipulation in bash.