I have a filename which ends with .zip
and I wanted just the filename without zip. Here I found a trick in bash.
$f="05 - Means-End Analysis Videos.zip" $echo "${f%*.zip}" 05 - Means-End Analysis Videos
What is happening here? How come %*.zip
is removing my extension?
Delete the shortest match of string
in $var
from the beginning:
${var#string}
Delete the longest match of string
in $var
from the beginning:
${var##string}
Delete the shortest match of string
in $var
from the end:
${var%string}
Delete the longest match of string
in $var
from the end:
${var%%string}
Try:
var=foobarbar echo "${var%b*r}" > foobar echo "${var%%b*r}" > foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With