tret
1
Hey guys, Can sed or another command be used to examine a path such as
/home/test/blah/blah
and check to see if the last character is a "/" and if so remove it
So this is what should happen:
/home/test/blah/blah
nothing happens, this is ok
/home/test/blah/blah/
the "/" at the end is removed and the string becomes
/home/test/blah/blah
Thanks all
Yes:
$ p=/home/test/blah/blah/
$ printf "%s\n" "${p%/}"
/home/test/blah/blah
$ p=/home/test/blah/blah
$ printf "%s\n" "${p%/}"
/home/test/blah/blah
Ikon
3
echo "/home/test/blah/blah/" | sed 's/\/$//'
/home/test/blah/blah
var=/home/test/blah/blah/
echo $var| sed 's%/$%%'
echo ${var%%/}
tret
5
This one works well, thanks everyone for your help!
era
6
Actually radoulov's solution (also posted in a variant by danmero) is superior.
Since the pattern can only match a single character, you only need one %:
newvar=${var%/}