Openunix.eu
Using Bash array
- starting an array
declare -a aray=( "fr.tuck" "marion" "robin")
- adding to an array
aray=("${array[@]}" "big john")
- printing an array
echo ${array[@]}
- Complete solution
#!/bin/bash
index=0
echo "The counting index for loop is set to: $index"
sleep 1
echo "Using the first column from a csv file for the array"
awk -F\; 'NF > 0 {print $1}' file.csv>file.ready
while read line
do
echo "Printing index in the loop: $index "
sleep 1
if [ $index == 0 ]
then
echo "starting a field with $line value"
sleep 1
declare -a array=($line)
else
echo "adding $line to the field "
sleep 1
array=("${array[@]}" "$line")
fi
index=$(($index+1))
echo "currently the field looks this:"
echo ${array[@]}
done<file.ready
echo "The array is complete:"
echo ${array[@]}
Powered by NetBSD. Running on a toaster.