I have this script who automatically add new values with a determined index o the array.
#!/bin/bash
declare -A DATA
DATA[sid0]='aaaa'
DATA[sid1]='bbbb'
DATA[sid2]='cccc'
function newserver {
sidtotal=0
indexcount=0
for indexcount in "${!DATA[@]}"
do
if [[ $indexcount == sid* ]]
then
sidtotal=$((sidtotal+1))
fi
done
read -p "Name: " id
DATA["sid$((sidtotal))"]=$id
echo ${DATA[@]}
echo sidtotal= $sidtotal
read -p "Would like do add more data? [y - n]" MOREDATA
}
newserver
while [ "$MOREDATA" == y ];do
newserver
done
This script automatically add a new value on the data array on determined index....
I want to add the value id and the determined indexed array sidtotal but, i would like do add in to the script too, at the same moment when i add, the script.sh will add the line. Something like that.
.......
DATA[sid0]='aaaa'
DATA[sid1]='bbbb'
DATA[sid2]='cccc'
DATA[sid3]='newdata'
........
So when the script finish, the value will not disapear...