Jump to content

Shell Pipeline -- I still don't get it....

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Mentalbox

Mentalbox

    Newbie

  • Members
  • PipPip
  • 19 posts
I'm tempted to tell a small rant'ish story but I'll resist it.

I still don't get how to use a pipeline in a shell properly...
I understand the concept of transferring the output of command1 to command2's input, but that's all I get.

If I try something different than a text-searching command like grep, say
vi arg
, how would I do this?
If I would try
echo filename | vi
I'd get this response:

Quote

Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
So it seems to be the case that when command2 is receiving input from command1 through piping, it is not "parsed" as an argument, but rather only directly?
What's a work-around to this?
And much more importantly: what's the logic? ("teach a man to fish...")

In fact this is my general problem, and I think my only downer and problem when it comes to programming: I don't understand the logic and functions of certain symbols or syntaxes, and I never see an easily addressed explanation about these issues anywhere.
The only places I've seen such actual "references" explained, is very simple symbols explained in newbie tutorials (like 3 pages about how "<" is a starting tag and ">" an ending tag...), or very slow and spread-all-over explanations in books. Like you have to actually read the entire book and follow and analyze every god **** example in the book to get it, even if you're only gonna use 2% of the actual examples. I'm getting frustrated again:D

It feels like the world is becoming socialist: put 99% of the resources in making dumb people normal and **** the smart people, "they can educate themselves" and is the reason why I have 10 undeveloped interests and a minor ulcers.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
A few command line tools have old syntax quirks that have not changed since they were made. In this case you need to inform Vim that it will be reading from standard input:
echo "Hello World!" | vi -

"-" (or sometimes -stdin, --stdin) by it self in place of a file name often informs the program to read from standard input, so not is all lost by learning this method.

zcat, zip, gpg ... and other de-facto tools allow this.

ssh some@host.com 'cat text.tar.gz' | zcat - #pipe external gzip file to stdout as plaintext

Edited by Alexander, 29 September 2011 - 04:37 PM.
cat->echo

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
Mentalbox

Mentalbox

    Newbie

  • Members
  • PipPip
  • 19 posts
I tried stuff like '$1' etc as a supplied argument, but apparently must not have thought about just '-'.
Thanks for clearing it up with an accurate answer (and with illustrations/examples) and that actually works too:w00t:
Problem solved.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users