variable_list="
any:any:-a -b -c any
one:one:-c -b -f -m mul
mul:one:-c -b -f -m mul
"
for f in `echo $variable_list`
do
c1=`echo $f | cut -d':' -f1`;
c2=`echo $f | cut -d':' -f2`;
c3=`echo $f | cut -d':' -f3-`;
echo "c1==>$c1 and c2==>$c2 and c3==>$c3";
#exit 0; ###I made mistake here
done;
预期输出:
c1==>any and c2==>any and c3==>-a -b -c any
c1==>one and c2==>one and c3==>-c -b -f -m mul
c1==>mul and c2==>one and c3==>-c -b -f -m mul
编辑1:
我意识到我在使用脚本时很愚蠢,并且在第一次迭代时我exit 0
只测试第一行,因为我有很多真实的。它按照它必须的方式工作。
我可以通过维护variable_list
而不修改输入的格式/方式来实现上述输出吗?
(我正在使用 bash)