"While read" problem

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

"While read" problem

Post by mudasir »

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
LinuxFreaK
Site Admin
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
Location: Karachi
Contact:

Re:

Post by LinuxFreaK »

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
Post Reply