Why does this code works without cat ?

R

Rainer Weikusat

[...]

Funny how people always seem to misinterpret something such that it
doesn't make any sense and then try to hold the person who wrote it
responsible for that ...

I don think I misinterpreted anything, unless it was the voices in your
head. I´m not psychic you know, and my amulet of ESP is out of order. I
do know what I read.
The original claim was:

Furthermore, [cat instead of file redirection] keeps the overall flow
of information on a pipeline running from left to right, rather than
zig-zagging.

Uh no? At least your reply (which I reacted on) was not a reply to this
claim. Therefore, the rest of your current reply is irrelevant.

I´ĺl assume it´s a misreading on your part, but this is a technical
newsgroup where accuracy is appreciated. Please do read what is written.
What you replied to actually was an argument in favor of your position,
but it seems you managed to interpret it as an argument against your
position.

I suggest that you read the explanation I gave (both of them,
actually) ...
 
R

Rainer Weikusat

Martijn Lievaart said:
You're trolling me, right?

Ok, spelled out again: Your _assumption_ about my intention is wrong.
This is partially my fault because I could have made this clearer (as
detailed in my 2n post on this), however, that doesn't make your
assumption any less wrong.
 
M

Martijn Lievaart

Ok, spelled out again: Your _assumption_ about my intention is wrong.
This is partially my fault because I could have made this clearer (as
detailed in my 2n post on this), however, that doesn't make your
assumption any less wrong.

You're making less and less sense.
The original claim was:

Furthermore, [cat instead of file redirection] keeps the overall
flow of information on a pipeline running from left to
right, rather than zig-zagging.

That indeed was said, but it was not what you reacted to.

You reacted to:
In bash, file redirection characters do not need to be at the end of a
command.

$ cat /etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012

$ cat </etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012

$ </etc/motd cat NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012

To which you said:
Unless I'm very much mistaken, the filename argument is in the same
position relative to the command both times ...

(conveniently omitting the third command line)

which is completely irrelevant to both the zigzagging claim and the file
redirection claim.

So what am I missing?

M4
 
R

Rainer Weikusat

Martijn Lievaart said:
Ok, spelled out again: Your _assumption_ about my intention is wrong.
This is partially my fault because I could have made this clearer (as
detailed in my 2n post on this), however, that doesn't make your
assumption any less wrong.

You're making less and less sense.
The original claim was:

Furthermore, [cat instead of file redirection] keeps the overall
flow of information on a pipeline running from left to
right, rather than zig-zagging.

That indeed was said, but it was not what you reacted to.

You reacted to:
In bash, file redirection characters do not need to be at the end of a
command.

$ cat /etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012

$ cat </etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012

$ </etc/motd cat NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012

To which you said:
Unless I'm very much mistaken, the filename argument is in the same
position relative to the command both times ...

Indeed. As I already explcitly wrote two times and implicitly pointed
out three times, my statement was supposed to refer to the wrong
'zig-zagging' claim and I was just using the two commands above as a
convenient example to illustrate that, without any intention
whatsoever to comment on the other content of the posting this example
came from.

[...]
which is completely irrelevant to both the zigzagging claim and the file
redirection claim.

The original claim was:

Furthermore, [cat instead of file redirection] keeps the overall
flow of information on a pipeline running from left to
right, rather than zig-zagging.

As illustrated in this nice example,

,----
| cat /etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33 EST 2012
|
| cat </etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
`----

it actually 'zig-zags' ('zig-zaggs'?) in either case because the
filename argument is to the right either way.
 
T

Tim McDaniel

The original claim was:

Furthermore, [cat instead of file redirection] keeps the overall
flow of information on a pipeline running from left to
right, rather than zig-zagging.

As illustrated in this nice example,

,----
| cat /etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33 EST 2012
|
| cat </etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
`----

it actually 'zig-zags' ('zig-zaggs'?) in either case because the
filename argument is to the right either way.

That's true, but

cat /etc/motd | some long command line with lots of options | maybe some other command

zig-zags much less than

some long command line with lots of options /etc/motd | maybe some other command
 
M

Martijn Lievaart

As illustrated in this nice example,

,----
| cat /etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
EST 2012 |
| cat </etc/motd NetBSD 5.1.2 (PANIX-XEN3U-USER) #0: Wed Feb 15 19:17:33
`----

it actually 'zig-zags' ('zig-zaggs'?) in either case because the
filename argument is to the right either way.

Ah got it. You used a post that shows that shows there is another way to
avoid the zig-zagging, incidentally using cat as an example, and snipped
the other way. Then you tried to make a point about cat, which was the
original topic, but not the topic of this post.

Yup, very clear. Not.

M4
 
P

Peter J. Holzer

You reacted to:


To which you said:


(conveniently omitting the third command line) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

which is completely irrelevant to both the zigzagging claim and the file
redirection claim.

So what am I missing?

My guess is that Rainer is missing something: The third command line,
which indeed doesn't zigzag, while the other two do.

(But personally I would prefer a uuoc to the third one in a shell
script: I suspect that most people don't know that shell feature)

hp
 
R

Randal L. Schwartz

xhoster> The point you so cleverly miss is that turning a cat into a
xhoster> grep is let easier, and less error-prone, than migrating a
xhoster> redirected file name from after the perl -e 'whatever' to
xhoster> before it, and adding a grep.

But you still don't need a cat.

On a sane shell, this works:

<somefile proggy arg arg

And when you want to turn that into a *concatenation* or a grep or other
filter, the file is already in teh right place.

No need for a useless use of cat.
 
R

Randal L. Schwartz

Eric> However, redirection comes with little bonuses:

Eric> {23:1} [0:0]% perl -wle 'print -s STDIN' </etc/passwd
Eric> 1814
Eric> {2048:2} [0:0]% cat /etc/passwd | perl -wle 'print -s STDIN'
Eric> 0

You're confusing what -s can return on a pipe vs a file. Very different.
 
E

Eric Pozharski

with said:
You're confusing what -s can return on a pipe vs a file. Very different.

Huh? "blame me, I've got used to be guilty of anything" (c) me.

p.s.

{2809:5} [0:0]% perl -wle 'print -s STDIN' </etc/passwd </etc/group
0

And who's confused now?
 
P

Peter J. Holzer

Eric> However, redirection comes with little bonuses:

Eric> {23:1} [0:0]% perl -wle 'print -s STDIN' </etc/passwd
Eric> 1814
Eric> {2048:2} [0:0]% cat /etc/passwd | perl -wle 'print -s STDIN'
Eric> 0

You're confusing what -s can return on a pipe vs a file. Very different.

I don't think that Eric is confusing anything. He is pointing out that
in the first example STDIN is a file handle to the file /etc/passwd So
you can determine its size, you can seek around in it, determin its
owner and permissions, etc.

Whereas in the second example STDIN is a file handle to a pipe. All you
can do with a pipe is read it sequentially.

They are, as you say, very different. Which is exactly what Eric was
showing, so I don't understand why you think he was confusing something.

hp
 
X

Xho Jingleheimerschmidt

Eric> However, redirection comes with little bonuses:

Eric> {23:1} [0:0]% perl -wle 'print -s STDIN'</etc/passwd
Eric> 1814
Eric> {2048:2} [0:0]% cat /etc/passwd | perl -wle 'print -s STDIN'
Eric> 0

You're confusing what -s can return on a pipe vs a file. Very different.

I'm pretty sure that that was his point.

Xho
 
P

Peter J. Holzer

with said:
You're confusing what -s can return on a pipe vs a file. Very different.

Huh? "blame me, I've got used to be guilty of anything" (c) me.

p.s.

{2809:5} [0:0]% perl -wle 'print -s STDIN' </etc/passwd </etc/group
0

And who's confused now?

Ok, you just proved me wrong: You *are* confused.

I admit that this particular zsh feature (it doesn't work in bash) is a
bit confusing:

When you use one input redirection, zsh (like any other shell) opens the
file, forks a child process, dups the filedescriptor to fd 0, and
finally execs the program.

But when you use two or more redirections, zsh opens all the files,
creates a pipe and forks two child processes: The first one concatenates
the files and sends them to the pipe, the second one dups the pipe's
file descriptor to 0 and execs the program.

So i zsh, writing

perl -wle 'print -s STDIN' </etc/passwd </etc/group

is almost equivalent to writing

cat /etc/passwd /etc/group | perl -wle 'print -s STDIN'

The only difference is that zsh doesn't actually call an external
executable named cat but performs the concatentation internally. Of
course that doesn't make any difference to perl.

hp
 
R

Rainer Weikusat

[...]
cat in front of any of these command is as useless as in front of
perl: They can either all work with files directly or use files the
shell opened for them

The point you so cleverly miss is that turning a cat into a grep is let
easier, and less error-prone, than migrating a redirected file name from
after the perl -e 'whatever' to before it, and adding a grep.

I'm not missing anything: You don't have a leg to stand on, you're
just a guy who advocates bad coding habits just because they are bad
coding habits.
 
E

Eric Pozharski

with said:
Ok, you just proved me wrong: You *are* confused.

I admit that this particular zsh feature (it doesn't work in bash) is a
bit confusing:
*SKIP* [[ *relevant* description of differences of various shells ]]

And zsh wins!

{6617:23} [0:0]% bash
{1:1} [0:0]$ perl -wle 'print -s STDIN' </etc/passwd </etc/group
1006
{26:2} [0:0]$ perl -nle '$aa++; END { print $aa }' </etc/passwd </etc/group
68
{56:3} [0:0]$ exit
{6889:29} [0:0]% perl -nle '$aa++; END { print $aa }' </etc/passwd </etc/group
105
{6900:30} [0:0]% wc /etc/passwd /etc/group
37 53 1814 /etc/passwd
68 68 1006 /etc/group
105 121 2820 total
 
E

Eric Pozharski

with said:
Quoth Eric Pozharski <[email protected]>:
Define 'wins'. If you mean 'produces a confusing and unexpected result
as a consequence of trying to be too clever', then yes, I agree.

If that would be addressed to some weak mind, then such mind would spill
something along the lines "OH YOU *ARE* SO CONFUSED!!ONEONE". But I
don't think you're confused. You're trolling, read below.

*SKIP* [[ that's irrelevant already ]]
foo 3>&2 2>&1 >&3 3>&- | bar

Wait a second. If that thread would have anything like a goal-post,
that would clearly constitute goal-post moving. All that in skipped had
nothing to do with redirecting *output*. We were talking redirecting
input.

cat /etc/passwd /etc/group | wc
wc </etc/passwd </etc/group
wc /etc/passwd /etc/group

That should prduce same result, shouldn't it?
 
T

Tim McDaniel

Wait a second. If that thread would have anything like a goal-post,
that would clearly constitute goal-post moving. All that in skipped
had nothing to do with redirecting *output*. We were talking
redirecting input.

I'm sorry. I had not realized that we're not allow to discuss
redirecting output. Thank you for clarifying.
cat /etc/passwd /etc/group | wc
wc </etc/passwd </etc/group
wc /etc/passwd /etc/group

That should prduce same result, shouldn't it?

Leaving aside whether the model of redirection should have automatic
catting (zsh, you say) or just overriding (sh, bash), "wc" when given
file names produces one line of output per file and each line includes
the filename, and if it has more than one filename argument, it adds a
line of totals.
 
E

Eric Pozharski

with said:
Quoth Eric Pozharski <[email protected]>:
No, it shouldn't. If the final redirection involving fd 0 is
'</etc/group' then fd 0 should end up attached to /etc/group, not to a
pipe from some random process that might happen to produce the data in
/etc/group at some point.

The only reason for this could be POSIX. Any reference, please?

I admit, concatenating multiple input redirections makes zsh cooler.
OTOH, the only mention of multiple 'word's for bash I've found is that
'word' is subject to expansion and if that expansion resulsts in multiple
'word's then bash explicitly fails. OTOOH, zsh clearly explains MULTIOS
effects (being it on or off).

I think that bash people has considered what to do with multiple
confronting redirections. And found that it would be too hard to worth
a try. And in order to *hide* that purely ad hoc decision they didn't
mention that in docs. What makes bash lame.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top