我想用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
但是,我想这样这样做,用回声变量内部引号:
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
我似乎无法正确地得到报价。可以实现我想要的吗?
谢谢!
只需使用单引号,并确保将半隆放在每个done
之前。
cmd='for i in {1..2}; do
for j in {1..2}; do
echo $i $j >> tmp.txt;
done;
done'
eval $cmd