Skip to main content
t=lkj
echo ${t:0:${#t}-1}

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

For instance, dashdash isn't able to parse even

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

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

t=lkj
echo ${t:0:${#t}-1}

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

For instance, dash isn't able to parse even

echo ${t:0:$(expr ${#t} - 1)}
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

Source Link
Ángel
  • 3.8k
  • 1
  • 16
  • 19

t=lkj
echo ${t:0:${#t}-1}

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

For instance, dash isn't able to parse even

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