We help IT Professionals succeed at work.

feed output of command to another command within the same prompt line?

jedblack
jedblack asked
on
Medium Priority
369 Views
Last Modified: 2012-05-12
hi all,

i'm sure this is simple, but i cant figure it out...

I am doing an rpm search for gdb and its giving me a couple entries, I tail the entries to give me one result.  Instead of copy/paste the result into another rpm command, I just want to feed/append it to a command within the same line in the prompt...

for example, i get this...

[root@build ~]# rpm -qa|grep -i gdb|tail -1
gdb-7.1-29.el6_0.1.x86_64
[root@build ~]#


i was to do something like this...
[root@build ~]# rpm -qa|grep -i gdb|tail -1 >> rpm -ql


I just cant remember how...really dont want to instantiate a variable to hold the output, there must be some redirection kung-fu i'm forgetting...
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
do you mean
rpm -qa|grep -i gdb|tail -1|rpm -ql
or something else?
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
or do you mean
rpm -ql `rpm -qa|grep -i gdb|tail -1`
CERTIFIED EXPERT

Commented:
As Ozo has put it
rpm -ql $(rpm -qa|grep -i gdb|tail -1)

But it would depend upon your macro settings whether this command would be successful or not.  You may need to chop off a part of RPM name for query ql to run

Author

Commented:
@ozo..

not quite...

its a little backwards, i would like to just work in sequence by sending the output to rpm -qa without having to fork off with backticks...
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
piping output with | also forks
just running the rpm -qa command does a fork
what is the command you want to perform?
rpm -qa|grep -i gdb|tail -1|xargs rpm -ql
might be another interpretation of your question

Author

Commented:
@ozo,

Thanks, exactly what i wanted...dint even think about xargs/exec -- the other way works just fine - but just a PITA -- you do an rpm -qa grep something, then tail it and then realize you have to put something in front of it and wrap the previous stuff in backticks..etc... just so much faster IMO to throw something on the end like with xargs...

thanks !

Explore More ContentExplore courses, solutions, and other research materials related to this topic.