I'm trying to perform a parameter substitution that strips everything from the first -
char to the end of a string like so: v0.1-bla-hblah-232 -> v0.1
So I'm using the following script:
#!/usr/bin/env bash
project_version=$(git describe --tags --long)
clean_version=${project_version%-$}
echo "$project_version"
echo "$clean_version"
If I run this, it does not work:
test λ ./revisioncount.sh
v0.1-2-g2ff1e73
v0.1-2-g2ff1e73
Seems that the $
atom is not being picked up by bash. backslashing it does not work either: \$
.
Now if I change the substitution line to this:
clean_version=${project_version%%-*}
Then it works:
test λ ./revisioncount.sh
v0.1-2-g2ff1e73
v0.1
How can I use the $
(which matches the end of the string) to achieve the desired effect?
$
matches end of string in many regular expression languages, but not (afaik) inbash
parameter substitution patterns. Second, even if it did work, your first pattern is "hyphen followed by end of string, with no characters in between", which would not match any of your strings.-.*$
.