help-bash
[Top][All Lists]
Advanced

[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: Lane Schwartz
Subject: Re: [Help-bash] What is going on here? Line with multiple < redirects
Date: Mon, 14 Dec 2015 11:49:57 -0600

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 sounds like you're suggesting that bash thinks that I'm asking for three
separate stdin redirects to be sent to part3.py, and given that's not
possible it chooses one of them (sample.txt).

That would appear to be consistent with the output I'm getting.

Thanks,
Lane



On Mon, Dec 14, 2015 at 11:34 AM, John Kearney <address@hidden> wrote:

> Part2 and 1 won't be executed in this example anyway, they would just be
> treated as text file and their content sent to the stain of part3.
>
> As to why you only see the content of one of the files. It's because you
> can only have one stdin. And the one that is chosen depends on the order in
> which bash parses them.
> Sorry I can't remember the order off the top of my head, I think it's
> right to left though.
>
> To redirect the executed output an app you have to pipe it e.g.
> Part1.py l part3.py
>
> To redirect the output of multiple scripts to the stdin of one
> {
> Part2.py
> Part1.py
> Cat sample.txt
> } l part3.py
>
> Or if the intent was to have each script to modify and pipe on it Coul
> look more like this
> Part1.py < sample.txt | part2.py l part3.py
> I teach a class that includes intro to Bash. One of my students tried
> something I'd never seen before, and I haven't been able to make sense of
> how Bash is parsing this (admittedly bizarre) command.
>
> $ ./part3.py < ./part2.py < ./part1.py < sample.txt
>
> In this example, part3.py appears to directly take sample.txt as input, and
> part2.py and part1.py appear to not execute.
>
> Any help figuring out what's going on would be appreciated. The complete
> steps to reproduce follow:
>
> $ seq 10 > sample.txt
>
> part1.py:
>
> #!/usr/bin/python3
> >
> >
> > import sys
> > import os
> >
> > os.mknod("part1_ran1.txt")
> >
> > for line in sys.stdin:
> >     print("PART1: {}".format(line.strip()))
>
>
>
> part2.py:
>
> #!/usr/bin/python3
> >
> >
> > import sys
> > import os
> >
> > os.mknod("part2_ran1.txt")
> >
> > for line in sys.stdin:
> >     print("PART2: {}".format(line.strip()))
>
>
>
> part3.py:
>
> #!/usr/bin/python3
> >
> >
> > import sys
> > import os
> >
> > os.mknod("part3_ran1.txt")
> >
> > for line in sys.stdin:
> >     print("PART3: {}".format(line.strip()))
>
>
>
>  $  ./part3.py < ./part2.py < ./part1.py < sample.txt
>
> PART3: 1
> > PART3: 2
> > PART3: 3
> > PART3: 4
> > PART3: 5
> > PART3: 6
> > PART3: 7
> > PART3: 8
> > PART3: 9
> > PART3: 10
>
>
> $ ls
>
> > part1.py  part2.py  part3.py  part3_ran.txt  sample.txt
>



-- 
When a place gets crowded enough to require ID's, social collapse is not
far away.  It is time to go elsewhere.  The best thing about space travel
is that it made it possible to go elsewhere.
                -- R.A. Heinlein, "Time Enough For Love"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]