Skip to main content
2 of 2
add details on bash/dash, refer to bash directly
t=lkj
echo ${t:0:${#t}-1}

You get a substring from 0 to the string length -1. Note however that this substraction is bash specific, and won't work on other shells.

For instance, dash isn't able to parse even

echo ${t:0:$(expr ${#t} - 1)}

For example, on Ubuntu, /bin/sh is dash

Ángel
  • 3.8k
  • 1
  • 16
  • 19