I writte the following script
load function should set the array disk[a]=1
and disk[b]=2
and so on
Then the function out should print the array ${disk[a]}
, and ${disk[b]}
, and so on
But what we get from function out is always the number 4
Instead, I want to get the following:
1
2
3
4
What is wrong here ?
How to fix it so function out will print:
1
2
3
4
the script:
#!/bin/bash
function load
{
counter=1
for input in a b c d
do
disk[$input]=$counter
let counter=$counter+1
echo ${disk[$input]}
done
}
function out
{
counter=1
for input in a b c d
do
echo ${disk[$input]}
let counter=$counter+1
done
}
echo "run function load"
load
echo "run function out"
out
the output:
./test
run function load
1
2
3
4
run function out
4
4
4
4