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
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?
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!
Summary: To give a short description what i am doing in the script is reading from a regular text file for the directory structure and changing it to another format and creating the structure, but the problem ...
Summary: Hello, here is my issue - I am running a script with a while loop. I have an awk statement within the while loop that uses an incremented variable. the script does not like me to use a variable in t...
Summary: Hello, I have a file containig DHCP lease information like the following: 02/01/2007 9:57:32 name/dhcp/1 Activity Protocol 0 04995 10.10.10.12 Lease renewed to MAC: '1,6,00:09:ef:00:32:09' packet 'R...