Hi,
does anyone know how to get the last characters of a string?
in bash.
Thanks
Bash last char of a string
-
chris
- Site Admin
- Posts: 216
- Joined: Mon Jul 21, 2008 9:52 am
Re: Bash last char of a string
Found a resolution:
This gives the last character:
This gives the last character:
Code: Select all
echo "${FILENAME:$((${#str}-1)):1}"-
chris
- Site Admin
- Posts: 216
- Joined: Mon Jul 21, 2008 9:52 am
Re: Bash last char of a string
you can also use:
Just remember that the last character can sometimes be a whitespace ( space, newline ...)
Code: Select all
echo ${STRING: -1}