linux - Removing everything but filename extension -
this question has answer here:
- extract filename , extension in bash 34 answers
let's have string:
x=file.tar.sh
i know how remove last n-characters. (removing last 3 characters:
${x: -3}
but doesn't work files different suffix lengths. (len .tar != len .sh)
i tackle removing until last dot. i've tried this:
${x##.}
this removes longest matching until "." somehow returns full string without removing anything?
try this:
x=file.tar.sh echo ${x##*.}
this print sh
if want tar.sh
, then:
echo ${x#*.}
here *
matches set of characters before occurrence of .
Comments
Post a Comment