The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with socket reading swap007 UNIX for Advanced & Expert Users 2 05-20-2008 10:08 PM
Problem reading a 4mm tape drive tdpearson AIX 2 05-24-2007 09:34 AM
problem in reading file using fread arunkumar_mca High Level Programming 4 10-30-2006 05:02 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 02:25 AM
Reading a CSV file into shell variables problem multidogzoomom Shell Programming and Scripting 6 10-11-2005 01:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-19-2006
Registered User
 

Join Date: Jun 2006
Posts: 8
help me ...problem in reading a file

hi,
while reading a file line by line

# name of the script is scriptrd

while read line
do
echo $line
done


while executing
bash$ ./scriptrd
if i give the input as
*

the output is like it displays the contents of the current directory

i jus wanted it to print as *


can anybody help me in this?
Reply With Quote
Forum Sponsor
  #2  
Old 06-19-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Code:
#! /bin/ksh
set -f
while read line
do
echo $line
done
Look into man ksh for the -f option under set. Or look for noglob.
Reply With Quote
  #3  
Old 06-19-2006
Registered User
 

Join Date: Jun 2006
Posts: 4
Hi,

Try following

#!/bin/ksh

cat <filename> | while read record
do

echo $record

done

Best Regards,
Sridhar M

Quote:
Originally Posted by brkavi_in
hi,
while reading a file line by line

# name of the script is scriptrd

while read line
do
echo $line
done


while executing
bash$ ./scriptrd
if i give the input as
*

the output is like it displays the contents of the current directory

i jus wanted it to print as *


can anybody help me in this?
Reply With Quote
  #4  
Old 06-19-2006
Registered User
 

Join Date: Jun 2006
Posts: 8
Hi vino,
that was perfectly working....thank you very much.
sridhar,that code results in the same error....but thanks for responding.

Both of you have worked it out in ksh...
but it works in bash too.
is that shell specific or what? whatz the difference?

Thanks and Regards,
Kavitha
Reply With Quote
  #5  
Old 06-19-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Yes it does work with bash and ksh. noglob is not shell specific. But if you go into other shells say zsh, then noglob does not exist (Atleast I couldnot find it in the man pages).
Reply With Quote
  #6  
Old 06-19-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Another solution :
Code:
#! /bin/ksh
while read line
do
echo "$line"
done

Jean-Pierre.
Reply With Quote
  #7  
Old 06-19-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,638
Quote:
Originally Posted by vino
Yes it does work with bash and ksh. noglob is not shell specific. But if you go into other shells say zsh, then noglob does not exist (Atleast I couldnot find it in the man pages).

I have a feeling it is there but it might be in the zshbuiltins man page.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0