I would like to delete the last character of a string, I tried this little script :
#! /bin/sh
t="lkj"
t=${t:-2}
echo $t
but it prints "lkj", what I am doing wrong? Thank you in advance!
I would like to delete the last character of a string, I tried this little script :
but it prints "lkj", what I am doing wrong? Thank you in advance! |
|||||
|
In a POSIX shell, the syntax Note that in |
|||
|
With
Example:
|
|||||
|
for removing the last
so for example you can delete the last character
from
UPDATE: if you don't know the length of the string, try:
|
|||||||||
|
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,
For example, on Ubuntu, |
||||
|
It is easy enough to do using regular expression:
|
|||
|