Mittwoch, 6. Mai 2015

Get the extension of a filename

Every now and then, one needs to decide upon a file its extension what to do.

This is what i've added as tui-str-extension:
out=""
FN=$( echo "$1" | sed s," ","",g)    # Remove any spaces and make it a single string
for chance in $(echo "$FN"|sed s,"\."," ",g)    # Use dots as string seperators
do    out="$chance"
done
if [ "$out" = "$FN" ]
then    echo ""
else     echo "${out%\ /}"     # Remove any tailing or single space
fi
Hope you like it :)

Keine Kommentare: