I am looking for a solution to eliminate square brackets in a Bash string. For instance, consider the string:
ldr r3, [r0,#8]!
However I am not sure how to eliminate the '[' and ']'. I would like to eliminate all symbols in the most elegant way possible, such as:
str="ldr r3, [r0,#8]!"
echo ${str//[,.!]/}
but with square brackets inclusive. How can this be accomplished?
Another clean solution is tr:
tr: Translate, squeeze, and/or delete characters from standard input, writing to standard output.
where
-d, --delete delete characters in SET1, do not translate
With your example:
str="ldr r3, [r0,#8]!"
echo $str | tr -d "[]"
the output is:
ldr r3, r0,#8!
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