Lockon2000
Lockon2000

Reputation: 363

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.

Upvotes: 3

Views: 136

Answers (1)

Wintermute
Wintermute

Reputation: 44063

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

Upvotes: 3

Related Questions