Reputation: 1193
I try to find a substring of a string.
If I have the string try-30/16
, I want to get the 30
string.
so I wrote the next:
n=${"'$b'":'-':'/'}
where $b is a variable I assign before this command. It gives the next:
bad substitution.
How I can do it?
Upvotes: 2
Views: 127
Reputation: 785156
You can also do:
[[ $b =~ [^-]+-([0-9]+) ]] && echo "${BASH_REMATCH[1]}"
OUTPUT:
30
Upvotes: 2