Hello,
I've made a simple associative arrays implementation in rc shell script.
Thanks to bnwr on irc for the idea with odd and even indices.
What do you think?
I'm rc newbie and would like to improve my skills. Any feedback would be
appreciated.
Thanks!
#!/usr/local/plan9/bin/rc
path=$PLAN9/bin
# List with odd items as keys and even items as values
data=('foo' 'bar' \
'bar' 'baz' \
'test' 'passed' \
'foo' 'one more bar' \
'dummy' 'qwerty' \
'quuix' 'dummy')
fn get {
if (! ~ $#* 0) {
k=1
v=0
while(test $k -le $#map) {
if (~ $1 $map($k)) {
v=`{echo $k + 1|bc}
}
k=`{echo $k + 2|bc}
}
if (! ~ $v 0)
echo $map($v)
}
}
map=$data get $1