Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute Linux nested command line tersely?

Here nested command line means one command's output is another command's input. For example below:

$ CmdA

output1 output2 output3...

Now I want to run CmdB which use the output of CmdA as arguments. So How to run CmdB tersely instead of using

$ CmdB output1 output2 output3...

I have an actual problem now:

$ python-config --cflags --ldflags

-I/usr/include/python2.7 -I/usr/include/python2.7 -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv
-lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic

As you see, there are many items generated from command python-config. If I compile a .cpp source file, i have to write all the items like

gcc test.cpp -I/usr/include/python2.7 -fno-strict-aliasing -02 -g -pipe........-o test, So i just want to find a simple way to execute the caller command.

Thanks for tips!

like image 738
Jason Avatar asked Nov 30 '25 01:11

Jason


2 Answers

gcc test.cpp `python-config --cflags --ldflags`

More: Command Substitution

like image 147
N 1.1 Avatar answered Dec 02 '25 16:12

N 1.1


You can give parameters to another command by using backticks or $():

$ uname -r
2.6.38-020638rc5-generic
$ ls /lib/modules/`uname -r`/
build              modules.builtin.bin  modules.inputmap   modules.softdep
initrd             modules.ccwmap       modules.isapnpmap  modules.symbols
kernel             modules.dep          modules.ofmap      modules.symbols.bin
modules.alias      modules.dep.bin      modules.order      modules.usbmap
modules.alias.bin  modules.devname      modules.pcimap
modules.builtin    modules.ieee1394map  modules.seriomap
$ ls /lib/modules/$(uname -r)/
build              modules.builtin.bin  modules.inputmap   modules.softdep
initrd             modules.ccwmap       modules.isapnpmap  modules.symbols
kernel             modules.dep          modules.ofmap      modules.symbols.bin
modules.alias      modules.dep.bin      modules.order      modules.usbmap
modules.alias.bin  modules.devname      modules.pcimap
modules.builtin    modules.ieee1394map  modules.seriomap
$ 

Try gcc test.cpp $(python-config --cflags --ldflags) -o test

like image 23
sarnold Avatar answered Dec 02 '25 15:12

sarnold