我想将我的shell脚本转换为使用datadriven方法。但是由于在任何shell中都没有“表格”类型的值(我知道),有什么建议替代方法来做到这一点?Datadriven shell编程?建议,请
我正在寻找的是解决方案,将允许人们做这样的事情:
animals = [['horse', 300 'brown'],
['cat', 3, 'black'],
['elephant', 3000, 'grey'],
['mouse', 0.3, 'grey']]
for a in animals ; do
echo "A typical $a[1] is $a[3] and weighs about $a[2] kilograms."
done
更确切地说,我想尝试一些命令,看看其中的一个是可用的,然后发送参数:
commands = [['c1', '-m', '-i'],
['c2', '-message', '-icon'],
['c3', '/m', '/i']]
for c in commands ; do
if exists c[1] ; then
command = c[1]
message_option = c[2]
icon_option = c[3]
break;
fi
done
$command $message_option "message" $icon_option icon
为什么不把你的'表'数据放到一个文件中,然后用'awk'或类似的程序读取它呢? – VM17
你正在使用哪个外壳? 'bash','ksh'或'zsh'? – Inian
我正在考虑'python',但是因为可移植性问题而决定不使用它。所以我的做法是'bash'。该脚本需要做很多其他的事情,但是探索与'awk'结合会很有趣,因为它也可以“随处可见”。那么一个shell脚本如何调用'awk'来做这个例子(我将更新它以更精确地指出我需要做什么)? – thoni56