Thursday, March 8, 2012

Hashes in shell


Might be one of the way to use “hashes” in ksh

It’s somewhat difficult to use hashes in bash[3* version], however easily possible in korn shell with below code !

#!/bin/ksh
typeset -A newmap
name="mandar"
id="111515"

newmap["name"]=$name
newmap["id"]=$id

echo "${newmap["id"]}"


Might be one of the way to use “array_push” method in ksh:

[root@cllin11 ~]# vim array_push.sh
#!/bin/ksh
typeset -A newmap
map_cnt=0

policy_list=`/usr/openv/netbackup/bin/admincmd/bppllist -l`

for pol in $policy_list
{
    newmap["$map_cnt"]=$pol
    map_cnt=` expr $map_cnt + 1 `
}

i=0
while [ $i -lt $map_cnt ]
do
    echo "${newmap["$i"]}"
    i=` expr $i + 1 `
done


No comments:

Post a Comment