LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   chaining multiple commands?? (https://www.linuxquestions.org/questions/linux-general-1/chaining-multiple-commands-62017/)

puzz_1 05-27-2003 12:41 AM

chaining multiple commands??
 
how do you pipe output from one command to another?

something like

which mplayer | rpm -qf

I am trying to find out which rpm mplayer belogns to.....but it doesn't work
neither does

which mplayer | rpm -qf -

help.....

whansard 05-27-2003 01:05 AM

you can rpm -qa|grep mplayer

born4linux 05-27-2003 01:06 AM

or

rpm -qf $(which mplayer)

if that's what u meant in ur post.

puzz_1 05-27-2003 01:53 AM

Well I know this will work in this case. But I meant it as an example of how to use pipes to chain multiple commands. How do you do it in general though??

fancypiper 05-27-2003 01:55 AM

screwed up

fancypiper 05-27-2003 01:58 AM

You mean something like this?

<command> | <another command> ; <then do this command> | <yet another command>

or

<command> | <2nd command> | <3rd command> | <4th command>

A good article about it: Linux and the Tools Philosophy

MasterC 05-27-2003 02:07 AM

Or do you mean:
<command> | <take output from last command as input for this command> output

Cool

whansard 05-27-2003 05:21 AM

that rpm -qa|grep mplayer
is a pipe. rpm -qa lists all the packages installed.
here all that text is piped into grep which searches
it for the word mplayer, then when mplayer is found,
grep prints the line that it was found on.

in general a program that can send a stream of
text or bytes is sent to the input of another program
that does something to that data.

tar clfv - .|(cd /mnt/copy; tar xpf -)

another example to look at

kkempter 05-27-2003 10:57 AM

Try this :

rpm -q -a | grep mplayer

acid_kewpie 05-27-2003 11:32 AM

seeing as everyone else said exactly the same thing, i might as well

rpm -qa | grep mplayer :p

it's also wrong... but nevermind. actually answering the question though, a program can only be used with a pipe if that is how it is written. while it could be designed for rpm to accept a file name through a pipe it is not particuarly useful, and so presumably no one bothered implementing it. personally in your example i would have said

rpm -qf `which mplayer`

but obviously that was only used as an example. you've got the right idea, it just isn't possible in that example.


All times are GMT -5. The time now is 07:42 AM.