"While read" problem

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

"While read" problem

Postby mudasir » Fri Nov 02, 2007 6:39 pm

AOA,

i am facing a problem.
#!/bin/bash

cat /files/names.lst | while read line
do
set $line
fname=$1
lname=$2
echo First Name=$fname --- Last Name=$lname
done


This is what i am trying to do. When i run this it does not give any error on the other hand this command dont work also. A list of some KERNEL buitlin command get executed like.
This is the message i get after executing this file
PWD=/files
=line
KERNEL=version
MEM.STAT= memory addresses

and many other KERNEL related stuff


I got the idea of using this command from one of the post by LAMBDA.
Topic
http://linuxpakistan.net/forum2x/viewtopic.php?p=35962
Last post by LAMBDA

can any one help me out in this regards

my /files/name.lst file format is
Mudasir Mirza
Yasir Khan
Zohair Hasmi
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Re:

Postby LinuxFreaK » Thu Nov 08, 2007 10:38 pm

Dear mudasir,
Salam,

I believe you need to use while like this.

Code: Select all

#!/bin/bash

cat /files/names.lst | while read fname lname
do
echo First Name=$fname --- Last Name=$lname
done


FYI, http://wooledge.org/mywiki/BashFAQ

Best Regards.
Farrukh Ahmed
LinuxFreaK
Site Admin
 
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron