LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Nested-double loop error (https://www.linuxquestions.org/questions/programming-9/nested-double-loop-error-441945/)

Harry Seldon 05-05-2006 12:34 PM

Nested-double loop error
 
I have a nested loop in a shell script I'm writing. Both loops are reading from files. The outside loop works fine but the inner loop keeps giving me an error:

./loops[13]: insideline: not found.

It doesn't matter what name I give the variable, it always fails with this error. My script is below. Any help would be appreciated.

#! /bin/ksh -xv
#
# Testing loops

rm /userimport/userimport
rm /userimport/existingaccounts

# Edit the userimport file so that dupes are removed from the new file.
while line=$(line) # /userimport/userimport
do
templine=$line
echo $templine > /tmp/greptemp
while insideline=$(insideline) # /userimport/acctcompare
do
grep $insideline /tmp/greptemp
if [[ $? -eq 0 ]]
then
tempcount=1
fi
done < /userimport/acctcompare
if [[ $tempcount -eq 1 ]]
then
echo $line >> /userimport/userimport.sorted
else
echo $line >> /userimport/existingaccounts
fi
tempcount=0
done < /userimport/filedrive.alabama

ioerror 05-05-2006 01:38 PM

$(...) performs command substition, i.e. it runs whatever is in the parentheses as a command. Thus:

Quote:

while line=$(line) # /userimport/userimport
executes a command called "line" (which is fine, /usr/bin/line reads one line from stdin and writes it to stdout) and

Quote:

while insideline=$(insideline) # /userimport/acctcompare
executes a command called "insideline", which doesn't exist.

Change the latter to

Code:

while insideline=$(line) # /userimport/acctcompare
and it should be OK, though if you want to find unique lines in the file, then

Code:

sort /userimport/userimport | uniq
might be easier. Or maybe I missed something.

Harry Seldon 05-05-2006 02:04 PM

Quote:

while insideline=$(line) # /userimport/acctcompare
Awesome. That worked! I was always unsure of how that command worked (line), only that it did, so I can tuck that little nugget away for future use. I'm sorting out an application password file that is structured like /etc/passwd. In some cases, entries will appear unique because the password hashes are different but the user ID and home directories are the same, which can cause problems in the app. This is a convoluted way to move files around but if I can get the scripts working we should be able to minimize any hassles in the future. Thanks for your help.

Digital Surgeon 05-06-2006 05:15 PM

your insideline variable is not pluging in


All times are GMT -5. The time now is 01:14 AM.