I tried to figure out how to replace a string variable to '*'
a="bamtools/*/*bam_metric.summary.tsv"
## not working
echo ${a/*\*/}
I would like to see bam_metric.summary.tsv after substitution.
Try:
$ echo "${a/*[*]/}"
bam_metric.summary.tsv
Other parameter substitution ideas:
$ echo "${a##*\*}"
bam_metric.summary.tsv
$ echo "${a##*[*]}"
bam_metric.summary.tsv
[*] is a bracket expression, not a character class :-). [:space:] is a character class while [[:space:]] is a bracket expression containing a character class. That's POSIX terminology, I know there's other terminology out there (perl? PCRE? idk..) that refers to just about EVERYTHING (e.g. all 3 of [:space:], [[:space:]], and \s) as a character class but that terminology is clear as mud and so IMO best avoided.
echo "${a/*\*/}"unless you needed to remove the quotes. See mywiki.wooledge.org/Quotes.[[ "$a" =~ [^*]*$ ]] && echo "${BASH_REMATCH[0]}"