Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Similar functionality to `...` in linux shell in Windows

In Linux / Unix shells there is this syntax where you can execute a command and in this command are other commands which are executed first and then substituted so something like this:

gcc main.c `pkg-config --cflags --libs gtk+-3.0`

Here the pkg-..... gets executed first and then substituted with its output and then the overall command is executed

Is there some similar functionality in Windows PowerShell (and if possible cmd too as I work with both sometimes)

All that I know is that in PowerShell you can write something like this:

gcc main.c (pkg-config --cflags --libs gtk+-3.0)

But the problem with this is that the output of the secondary command is passed like a single continuous string so something like this "-mms-bitfields ....." and gcc doesn't recognize it as separate commands.

like image 384
Lockon2000 Avatar asked Mar 31 '26 20:03

Lockon2000


1 Answers

You can use the -split operator:

gcc main.c ((pkg-config --cflags --libs gtk+-3.0) -split " ")

Or possibly

gcc main.c ((pkg-config --cflags --libs gtk+-3.0) -split " +")

to avoid empty arguments in case there are multiple spaces between arguments in the output (although I don't think pkg-config does that).

The -split operator does precisely what it says on the tin: It splits what it is given at occurrences of the given pattern. That is to say,

PS C:\> "foo bar baz" -split " "
foo
bar
baz
like image 109
Wintermute Avatar answered Apr 02 '26 12:04

Wintermute



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!