What is the most effective way to get:
'a/b/c'
out of input string that can be any of the following:
'/a/b/c/'
'a/b/c/'
'/a/b/c'
'a/b/c'
in a bash script?
I don't know about "most effective", but if that string is stored in the variable a
(that is $a
expands to the string) you can do:
b=${a#/} # Remove possible leading /
c=${b%/} # Remove possible trailing /
to put the desired string in the variable c
. This doesn't work if your input string contains single quotes as you have written in the question, but I suspect you did not intend to indicate that such quotes are in the string.
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