Need some help with scripting. I'm new to it, please be kind and overly explanatory

I have a simple script in three parts:

  1. Search for files, get the results from the find command, pipe those results to sed to strip out the filename, and finally pipe those results to a file: pathlist.txt
  2. Read the contents, line by line, of pathlist.txt to an array in a bash script
  3. Use the array to create soft links to the entries in pathlist.txt.

I’ve got everything working as long as I don’t use step #2. If I define an array with hard values then the script runs, but if I use a while loop to read the file it just hangs. I’m assuming I have the syntax wrong for reading a file with a while loop. Here’s what I have:

Step 1:

find -H /mnt/restore/ -iname wphost.db | sed -e ‘s/wphost.db//’ > pathlist.txt

That works. I get exactly what I want in that file.

Step 2:

# Use while loop to read each line, which is a path, into the array
counter=0
while read line<pathlist.txt; do
pathlist[counter]=$line
((counter++))
done

I know this must be a basic question, but I’ve moved from Novell to Windows, back to Novell, and now Linux. Any help is appreciated. Please dumb it down, the internet is full of forums about linux with admins who give answers without any explanation at all.

Why don’t you save the result of 1 directly in an array and skip 2 and 3 ?

somearray=(`find -H /mnt/restore/ -iname wphost.db | sed -e 's/wphost.db//'`)

for f in ${somearray[li]} ; do
[/li]     whatever
done

Can you see the difference: (?)

#!/bin/bash
#
# Create a file with data:
echo -e "foo
bar
baz" > pathlist.txt

# Fill array from file:
declare -i counter=0
while read line ; do
    pathlist$counter]="$line"
    counter=$$counter + 1]
done <pathlist.txt

# Proof:
counter=0
while test -n "${pathlist$counter]}" ; do
    echo $counter ${pathlist$counter]}
    counter=$counter+1
done
exit 0

I did use different notations to increment the counter. This is possible because I declared it as a numerical integer.

Christ ona stick, gentlemen, both of your suggestions worked like gangbusters.

Thank you both so much for the help!