2

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!

3 Answers 3

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

More: Command Substitution

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

0

Is this what you're talking about?

$ cmdA | while read line; do cmdB $line; done

1 Comment

Sounds like he's looking for backquotes, since that's how "python-config" is intended to be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.