using pipe in shell script

unix

    Next

  • 1. cron and SMTP AUTH
    Is it possible for cron jobs which do generate something on stdout/stderr to use a secure SMTP AUTH email server on localhost and how ? I would like to reconfigure sendmail with SMTP AUTH on my solaris boxes but there are some issues with handling mails generated by cron jobs. Is it possible to tell cron to use a particular login/credential for sending emails to the local SMTP AUTH server ? Thanks, Thierry.

using pipe in shell script

Postby Ela » Thu, 03 Apr 2008 12:36:34 GMT

Dear all,

I found I cannot use a variable name as the input of the command "cat" 
followed by piping the result. Could any body tell me how to solve the 
problem?

cat $filename |\
        while read line
        do
        echo "$line read from $filename"
        done




Re: using pipe in shell script

Postby Gary R. Schmidt » Thu, 03 Apr 2008 14:41:25 GMT


Try:
while read line
do
   echo "$line read from $filename"
done < $filename

	Cheers,
		Gary	B-)

Re: using pipe in shell script

Postby Michael Schmarck » Thu, 03 Apr 2008 15:32:14 GMT




And what's the problem? Your code works just fine (with bash).
What does not work for you?

--($:~)-- cat $filename | while read line ; do echo "$line read from $filename" ; done
:set hlsearch read from .vimrc
--($:~)-- echo $filename
.vimrc

BTW: That was UUOC. Better to do:

while read line; do echo "$line read from $filename"; done < $filename

Michael

Re: using pipe in shell script

Postby Chris Mattern » Fri, 04 Apr 2008 01:06:51 GMT





Gary's solution is good for this specific problem.  In the more general
case, where there's no alternative to piping stdout into a loop, 
you'll avoid this problem by using ksh and not bash.


-- 
             Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Re: using pipe in shell script

Postby Michael Schmarck » Fri, 04 Apr 2008 02:47:51 GMT

 Chris Mattern < XXXX@XXXXX.COM >:


What problem? The code that's been posted by the OP works



But you're right though, Garys solution is better than the one
posted by the OP, as it avoids a UUOC.

Anyway - I'd *really* be interested in knowing the problem you talk
about.

Michael Schmarck
-- 
"You're just the sort of person I imagined marrying, when I was little...
except, y'know, not green... and without all the patches of fungus."
                -- Swamp Thing


Similar Threads:

1.using pipes in shell script

Hi,
I am told not to use pipes (|) in my shell scripts because using pipe is an 
expensive operation.  Is this true?
Would I get better performance if I execute one instruction and assign its 
output to a variable and then use that variable in the second instruction? 
instead of doing both insturuction on one line and piping the output of the 
first instruction to the second one?


Thanks

Al 


2.Checking Pipe Status Using Script At Comp.Unix.Shell FAQ

3.Piping into a shell script

Hello,

I want to write a shell script in bash, where I can pipe other commands 
and files through. Something like

cat textfile.txt | myscript.sh

myscript.sh should take the input and write it to a file. I tried it 
with read and a while loop, but if there are special characters in 
textfile.txt like backslashes, the output was allways not the same like 
the input. How can I do that?

Best regards
Marc

4.Copy files using filenames from text files with shell script or bash script

How can I do this????

I have the file "lista.txt", and this file have the next information:
     one.txt
     two.txt
     five.txt
    six.txt
-------------------
This files exist in the same directory that "list.txt", I would like to
copy this files to other directory

Using Windows the batch file would be like this:  for /f "tokens=*" %i
in (list.txt) do copy "%i" destdir\

How can I do something like that in UNIX??

Best Regards



Return to unix

 

Who is online

Users browsing this forum: No registered users and 48 guest