Reputation: 9622
I want to achieve this with bash:
for i in {1..2}
do
for j in {1..2}
do
echo $i $j >> tmp.txt
done
done
cat tmp.txt
1 1
1 2
2 1
2 2
However I want to do it like this with the echo variable inside quotes:
cmd="
for i in {1..2};
do for j in {1..2};
do echo \$i "\$j" '\$i' "'\$j'" \$i "'$j'" \'$i\' \"$j\" >> tmp.txt;
done;
done
"
eval $cmd
I can't seem to get the quotes right. Is it possible to achieve what I want?
Thank you!
Upvotes: 0
Views: 61
Reputation: 363577
Just use single quotes and be sure to put a semicolon before each done
.
cmd='for i in {1..2}; do
for j in {1..2}; do
echo $i $j >> tmp.txt;
done;
done'
eval $cmd
Upvotes: 3