Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve the last x characters of a string in Bash, you can use the following syntax:

${string: -x}

Here, the variable string contains the string from which you want to retrieve the last x characters. The -x specifies the number of characters you want to retrieve, counting from the end of the string. The space in between : and -x is important.

For example, if you want to retrieve the last four characters of a string hello world, you can use the following command:

$ echo ${string: -4}

This will output orld.