TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:3948] simple bash script - redirect pipe
>>> Christopher Palmer <reid@pconline.com> 02/05 4:15 PM >>>
>On Fri, 5 Feb 1999, Ben Luey wrote:
>> How do I control what is piped to a script?
>> I want to be able to type
>> `cat myfile |myscript'
>> and myscript will redirect the pipe (ie contents of myfile) to
someother
>> program.
>You don't want to pipe, you want to redirect. Try this:
>myscript < myfile
>That means, "Take 'myfile' as the input for 'myscript'".
If you really want to redirect stdin (standard input: something piped
to your program), you can do this:
#!/bin/sh
cat | otherprogram
but if you want to do something more with it you might want to write
it to a temp file first:
#!/bin/sh
cat > temp.stdin.$$
# do other stuff here
cat temp.stdin.$$ | otherprogram
# or do it here
rm -f temp.stdin.$$
or if you want to pipe it to another program and still be your
standard input, you can do this:
#!/bin/sh
cat > temp.stdin.$$
exec < temp.stdin.$$
# process standard input here
cat temp.stdin.$$ | otherprogram
# or do it here
rm -f temp.stdin.$$
Oh the fun you can have!
:)
Happy Friday,
Troy