Posts Tagged ‘chars’

If you want to get the last n characters of a string in bash, you can simply mix bash substrings – ${string:offset[:length]} – with bash string lengths – ${#string}. For example: str=”abcde” n=3 echo ${str:${#str} – $n} will print: cde