So I know that this has been asked a million times on StackExchange, but I am not able to implement the solutions in the other threads in my bash script. Probably I'm just too stupid to understand the answers, so please go easy on me.
For simplicity, the following code is equivalent with what I want to do:
for i in {1..5}
do
echo $2.svg | grep 'rect x="$i"' && do_something_if_$i_is_found
done
The issue here is that when I wrap $i in double quotes "$i" is treated like a string.
- I cannot use single quotes instead because I am looking for
x="5"
in$2.svg
- Escaping the double quotes inside of the single quotes make them a part of the string, i.e.
'rect x=\"$i\"'