我想用 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
但是我想用引号内的 echo 变量来做这样的事情:
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
我似乎无法正确引用引号。有没有可能实现我想要的?
谢谢!