[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] What is going on here? Line with multiple < redirects
From: |
Bob Proulx |
Subject: |
Re: [Help-bash] What is going on here? Line with multiple < redirects |
Date: |
Mon, 14 Dec 2015 15:25:08 -0700 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
Greg Wooledge wrote:
> Lane Schwartz wrote:
> > Thanks, John. The question isn't really how to do this the right way - I
> > know how to do that. The question is more how is bash processing this line?
>
> It processes each redirection in order, left to right. Since they are
> all stdin redirections ( < ) each subsequent one undoes the previous
> one's effect.
>
> There is no mystery here.
I just feel the need for more verbosity... :-)
$ ./part3.py < ./part2.py < ./part1.py < sample.txt
Process line from left to right looking only for file redirections
< -- redirection seen, next argument is a file, open it for reading
./part2.py -- file, open this for reading, redirect to stdin
(Report any errors that occurred due to the redirection.)
< -- redirection seen, next argument is a file, open it for reading
./part1.py -- file, open this for reading, redirect to stdin
(Report any errors that occurred due to the redirection.)
(This overrides the previous redirection.)
< -- redirection seen, next argument is a file, open it for reading
sample.txt -- file, open this for reading, redirect to stdin
(Report any errors that occurred due to the redirection.)
(This overrides the previous redirection.)
After other command line processing is done invoke the command.
./part3.py -- command to invoke with the above redirections
As each redirection is seen, the action it instructs is done. In the
above each of the actions overrides the previous. Only the last has
any effect.
It is mostly equivalent in result to:
$ ./part3.py < sample.txt
Except in the original if part1.py or part2.py are missing or if
permissions prevented the action or other things obviously there would
be an error because the redirection could not be completed.
Bob