Skip to content
Advertisement

String usage with {} in bash

I have a kind of the following strings

str1="aaa.bbb."

and

str2="aaa.ccc"

I wan to call:

echo ${str1%.*}
echo ${str2%.*}

in order to get

"aaa.bbb." for str1

and "aaa." for str2

what should I use as expression inside {}

Advertisement

Answer

Use it like this:

echo "${str1%.*}."
aaa.bbb.

echo "${str2%.*}."
aaa.
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement