Accessing last x characters of a string in Bash
I found out that with ${string:0:3} one can access the first 3 characters of a string. Is there a equivalently easy method to access the last three characters? gniourf_gniourf Last three characters of string : ${string: -3} or ${string:(-3)} (mind the space between : and -3 in the first form). Please refer to the Shell Parameter Expansion in the reference manual : ${parameter:offset} ${parameter:offset:length} Expands to up to length characters of parameter starting at the character specified by offset. If length is omitted, expands to the substring of parameter starting at the character