LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple redirect question? (https://www.linuxquestions.org/questions/programming-9/simple-redirect-question-548494/)

scsi.king 04-23-2007 11:46 PM

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

scsi.king 04-24-2007 12:08 AM

A Pipe almost works, but no End Of File?

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

Almost there....

ghostdog74 04-24-2007 12:23 AM

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


scsi.king 04-24-2007 01:44 AM

Got It - You were right! Thanks
 
Working fine.
Thanks


All times are GMT -5. The time now is 04:11 AM.