Re: pipe confusion

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Mon Apr 12 2004 - 09:35:24 AKDT

On Mon, 12 Apr 2004, Thomison, Lee wrote:

> Heya folks,
>
> Piping and redirection are sore troublesome topics for me. They
> shouldn't be, seems easy enough, but obviously not, so any help is
> appreciated.
>
> Keeping it simple, I have n number of hosts I want to execute a command
> (or shell script, even) on. These hosts are listed in a file
> ~/hostlist.
>
> What's wrong with
>
> rsh - ls < hostlist ! where ls is the command I want to
> execute on the remote systems.
>
> It looks like it has something to do with the stdin -not- feeding to
> '-', like I expect it to, but I'm having trouble getting past that.

You're right on the money: in order for that kind of redirection to work you
need a command that will accept arguments on STDIN. In this case, most
variants of rsh will *only* accept host arguments as an argument to the
command. The only way around this is for you to have a shell that will
perform an implied loop, substituting the '-' with each line of the redirected
file. The common ones that I know of simply won't do that.

Keep in mind that the '-' character has no magic meaning to most shells in
itself. Commands that use it as a synonym for STDIN (like tar) do so
explicitly, with no help from the shell.

A work-around (assuming POSIX/Borne shell):

  for host in `cat hostlist` ; do rsh $host ls ; done

        --Arthur Corliss
          Bolverk's Lair -- http://arthur.corlissfamily.org/
          Digital Mages -- http://www.digitalmages.com/
          "Live Free or Die, the Only Way to Live" -- NH State Motto
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Mon Apr 12 09:34:12 2004

This archive was generated by hypermail 2.1.8 : Mon Apr 12 2004 - 09:34:13 AKDT