Computing.Net > Forums > Unix > ksh while loop problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ksh while loop problem

Reply to Message Icon

Name: kevin
Date: June 9, 2003 at 08:14:23 Pacific
OS: Unix
CPU/Ram: G3
Comment:

Hey all,

This problem's been doing my head in, and I hoping that someone can point to me the error of my ways.

Korn shell script, that takes in a file with an unfixed size takign the following format:

N test Ireland
N test2 England
D test3 Japan

In my script I want to do something to where the first val is "N" and something different when the first val is "D" --- Here's my effort ----

while read -r val1 val2 val3
do
if [ "$val1"=="N" ]; then
echo NEW VALUE....
elif [ "$val1"=="D" ]; then
echo Deleting VALUE....
fi
done script_file_from_above

It always prints NEW VALUE... even when the first column is "D" -- Anyone see what I'm doing wrong?

Thanks,
kev.




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 9, 2003 at 08:20:08 Pacific
Reply:

Kev:

Try:

echo $NEWVALUE

I think you forgot $

Regards,

Nails


0

Response Number 2
Name: kevin
Date: June 9, 2003 at 08:24:18 Pacific
Reply:

What's happening is that it always goes into the first loop - the 'echo New Value' is just a test to see if if parses the file correctly.

The if loop where I perform a string comparison is where the problem lies, but I can't figure out why its not working - Any ideas?

Thanks,
Kev.


0

Response Number 3
Name: nails
Date: June 9, 2003 at 09:01:05 Pacific
Reply:

Kev:

Sorry, I should have read your original post closer.

On Solaris 7, I had to place spaces around the "==" signs. BTW, double equal signs are optional - single ones work as well.

Regards,

Nails


0

Response Number 4
Name: kevin
Date: June 9, 2003 at 09:08:51 Pacific
Reply:

Cheers - that worked finally!
Sometimes the way different OS versions read in data is a bit annoying - I spent 2 hours trying to fix that --- At least I know now in the future!

Thanks,
kev.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: ksh while loop problem

While loop stuck www.computing.net/answers/unix/while-loop-stuck/6389.html

AWK in a while loop www.computing.net/answers/unix/awk-in-a-while-loop/6669.html

Nested while loop www.computing.net/answers/unix/nested-while-loop/7684.html