LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-05-2006, 12:34 PM   #1
Harry Seldon
Member
 
Registered: Feb 2004
Distribution: SLES 9
Posts: 112

Rep: Reputation: 15
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

Last edited by Harry Seldon; 05-05-2006 at 12:37 PM.
 
Old 05-05-2006, 01:38 PM   #2
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 30
$(...) 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.

Last edited by ioerror; 05-05-2006 at 01:41 PM.
 
Old 05-05-2006, 02:04 PM   #3
Harry Seldon
Member
 
Registered: Feb 2004
Distribution: SLES 9
Posts: 112

Original Poster
Rep: Reputation: 15
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.
 
Old 05-06-2006, 05:15 PM   #4
Digital Surgeon
Member
 
Registered: Nov 2004
Location: Canada
Distribution: Ubuntu 7.10 - Gutsy Gibbon(Desktop Edition)
Posts: 184

Rep: Reputation: 30
your insideline variable is not pluging in
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to mount loop filesystem error with PCLinuxOS Pr9.1 sc123 Linux - Software 1 09-19-2008 11:08 AM
glxgears: Error: couldn't get an RGB, Double-buffered visual. koodoo Linux - Newbie 10 08-15-2008 10:06 PM
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 02:22 PM
Help! 2.4.29 + nptl = glibc error: cannot compute (long double), 77 Yerp Linux From Scratch 3 03-25-2005 06:28 PM
just installed CUPS printer is OK.. but can't print Error: loop in printcap on lpr soylentgreen Linux - Newbie 4 09-23-2004 10:41 AM


All times are GMT -5. The time now is 07:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration