LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-23-2007, 11:46 PM   #1
scsi.king
LQ Newbie
 
Registered: Apr 2007
Posts: 6

Rep: Reputation: 0
Red face Simple redirect question?


Hi,
If I create a file called dir.txt in my home directory using the following redirect: ls -l > dir.txt
and then run the following portion of my bash script, things go as planned.

while read line
do
echo -e "Line = $line\n"
done < dir.txt

The following does NOT work:

while read line
do
echo -e "Line = $line\n"
done < `ls -l`

If I try to redirect the 'ls -l' directly into my bash script I get an "ambiguous redirect" error. Could someone tell me why and what is the solution to this redirect problem.
Thanks
 
Old 04-24-2007, 12:08 AM   #2
scsi.king
LQ Newbie
 
Registered: Apr 2007
Posts: 6

Original Poster
Rep: Reputation: 0
A Pipe almost works, but no End Of File?

while read line
do
echo -e "Line = $line\n"
done | ls -l

Almost there....
 
Old 04-24-2007, 12:23 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by scsi.king
Hi,
If I create a file called dir.txt in my home directory using the following redirect: ls -l > dir.txt
and then run the following portion of my bash script, things go as planned.

while read line
do
echo -e "Line = $line\n"
done < dir.txt

The following does NOT work:

while read line
do
echo -e "Line = $line\n"
done < `ls -l`

If I try to redirect the 'ls -l' directly into my bash script I get an "ambiguous redirect" error. Could someone tell me why and what is the solution to this redirect problem.
Thanks
this should correct
Code:
ls -l | while read -r line
do
  echo ...
done
 
Old 04-24-2007, 01:44 AM   #4
scsi.king
LQ Newbie
 
Registered: Apr 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Smile Got It - You were right! Thanks

Working fine.
Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mod_rewrite, simple directory redirect? xconspirisist Linux - Software 3 12-20-2005 08:22 AM
Ubuntu Fluxbox simple question, simple answer? generallimptoes Linux - Software 3 09-26-2005 02:03 PM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM
simple bind and redirect example, please benazonafunk Linux - Networking 3 08-26-2003 07:43 AM
please help, simple question about redirect output kool Linux - General 4 03-18-2002 09:34 AM


All times are GMT -5. The time now is 01:47 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration