Hello, I am trying to teach myself shell programming so I am scripting a really cheesy addressbook sort of thing. I am having problems with for loops and arrays however.
In particular, I am having problems with the function that lists all contacts. The script sources a file with the contacts in it which looks like:
Darren="123 fake address way"
Darren="123 456 7890"
Darren="placeholder for notes"
Joe="234 another fake rd"
Joe="250 476 7773"
Joe="this is a note"
My function that adds the contacts adds them perfectly in this format, and a little loop adds 1 to each index of the "contact" array, but I can't get it to display them properly. Here's the relevant bit of the function:
if [ ! -e ~/.addbookdata ] # check for first time user
echo "There are no contacts listed"
echo "Contact data file has been created"
echo "You may now add contacts"
echo "All contacts:"
for index in 1 2 3 4 5
I am having problems with the echo statement, it works fine when I put in the actual name ie: "echo "$darren[index]" but what I need to have it do is cycle through all the contacts ie: contact, contact, etc...and cycle through the five contact indices for each contact which hold the actual address info.
What do I need to do here? Nested for loop? Any ideas? Even a bit of psuedo code might help me through this block...