Equivalent of Bash's $() on Windows?
up vote
3
down vote
favorite
On Bash, I can use a subshell to fill the result of one command into the next:
$ echo $(sub-command args)
and if $(sub-command args)
wrote foo
to standard out, then the above command would be equivalent to:
$ echo foo
Does Windows 7 have a way to do this in cmd.exe
?
The reason I want to do this is so I can easily run executables from npm's installation directory without having that directory on my path:
$ $(npm bin)/grunt build
windows bash
add a comment |
up vote
3
down vote
favorite
On Bash, I can use a subshell to fill the result of one command into the next:
$ echo $(sub-command args)
and if $(sub-command args)
wrote foo
to standard out, then the above command would be equivalent to:
$ echo foo
Does Windows 7 have a way to do this in cmd.exe
?
The reason I want to do this is so I can easily run executables from npm's installation directory without having that directory on my path:
$ $(npm bin)/grunt build
windows bash
1
In what shell on Windows? Are you running Bash on Windows? Should work the same as bash anywhere else. If this isn't bash, then the shell you are using matters. That is, powershell certainly supports subexpressions, using the exact same syntax even.
– Zoredache
Oct 20 '16 at 23:40
Good point. I meant incmd.exe
.
– Nick Heiner
Oct 24 '16 at 15:13
AFAIK cmd.exe has no support for sub-expressions.
– Zoredache
Oct 24 '16 at 16:54
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
On Bash, I can use a subshell to fill the result of one command into the next:
$ echo $(sub-command args)
and if $(sub-command args)
wrote foo
to standard out, then the above command would be equivalent to:
$ echo foo
Does Windows 7 have a way to do this in cmd.exe
?
The reason I want to do this is so I can easily run executables from npm's installation directory without having that directory on my path:
$ $(npm bin)/grunt build
windows bash
On Bash, I can use a subshell to fill the result of one command into the next:
$ echo $(sub-command args)
and if $(sub-command args)
wrote foo
to standard out, then the above command would be equivalent to:
$ echo foo
Does Windows 7 have a way to do this in cmd.exe
?
The reason I want to do this is so I can easily run executables from npm's installation directory without having that directory on my path:
$ $(npm bin)/grunt build
windows bash
windows bash
edited Oct 24 '16 at 15:13
asked Oct 20 '16 at 19:52
Nick Heiner
66251631
66251631
1
In what shell on Windows? Are you running Bash on Windows? Should work the same as bash anywhere else. If this isn't bash, then the shell you are using matters. That is, powershell certainly supports subexpressions, using the exact same syntax even.
– Zoredache
Oct 20 '16 at 23:40
Good point. I meant incmd.exe
.
– Nick Heiner
Oct 24 '16 at 15:13
AFAIK cmd.exe has no support for sub-expressions.
– Zoredache
Oct 24 '16 at 16:54
add a comment |
1
In what shell on Windows? Are you running Bash on Windows? Should work the same as bash anywhere else. If this isn't bash, then the shell you are using matters. That is, powershell certainly supports subexpressions, using the exact same syntax even.
– Zoredache
Oct 20 '16 at 23:40
Good point. I meant incmd.exe
.
– Nick Heiner
Oct 24 '16 at 15:13
AFAIK cmd.exe has no support for sub-expressions.
– Zoredache
Oct 24 '16 at 16:54
1
1
In what shell on Windows? Are you running Bash on Windows? Should work the same as bash anywhere else. If this isn't bash, then the shell you are using matters. That is, powershell certainly supports subexpressions, using the exact same syntax even.
– Zoredache
Oct 20 '16 at 23:40
In what shell on Windows? Are you running Bash on Windows? Should work the same as bash anywhere else. If this isn't bash, then the shell you are using matters. That is, powershell certainly supports subexpressions, using the exact same syntax even.
– Zoredache
Oct 20 '16 at 23:40
Good point. I meant in
cmd.exe
.– Nick Heiner
Oct 24 '16 at 15:13
Good point. I meant in
cmd.exe
.– Nick Heiner
Oct 24 '16 at 15:13
AFAIK cmd.exe has no support for sub-expressions.
– Zoredache
Oct 24 '16 at 16:54
AFAIK cmd.exe has no support for sub-expressions.
– Zoredache
Oct 24 '16 at 16:54
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
as they already stated in the comments, there is no native way of doing this with cmd. However there is a hack that you may use for your case (as npm bin
only returns one line):
for /F "tokens=*" %n IN ('npm bin') DO @(%ngrunt build)
or inside a batch file you have to duplicate the %
:
for /F "tokens=*" %%n IN ('npm bin') DO @(%%ngrunt build)
Alternatives
Batch
You could generate a script that receives the parameter and runs the command, something like
:: Takes the parameters and send to npm bin output
for /f "tokens=*" %%n in ('npm bin') do @(%%n%1 %2 %3 %4 %5)
Save it as npmbin.cmd in your path, then you could run:
npmbin.cmd grunt build
Powershell
For your case, you should be able to invoke it through powershell using the invoke-expression cmdlet:
iex "$(npm bin)grunt build"
I don't have npm on me right now, but I tested with other program and it looks like it would work.
Environment Variable
Anyway, I think the previous are very complicated "solutions", while you only want to simplify your command. I was wondering if you could create a global variable, say NPMBIN
and then use it for your commands:
%NPMBIN%grunt build
To extend this you could set up a task to set it programatically for your user (or eventually the computer) using setx
, some batch like:
for /f "tokens=*" %%n in ('npm bin') do @(setx NPMBIN %%n)
Hope it helps. Regards
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
as they already stated in the comments, there is no native way of doing this with cmd. However there is a hack that you may use for your case (as npm bin
only returns one line):
for /F "tokens=*" %n IN ('npm bin') DO @(%ngrunt build)
or inside a batch file you have to duplicate the %
:
for /F "tokens=*" %%n IN ('npm bin') DO @(%%ngrunt build)
Alternatives
Batch
You could generate a script that receives the parameter and runs the command, something like
:: Takes the parameters and send to npm bin output
for /f "tokens=*" %%n in ('npm bin') do @(%%n%1 %2 %3 %4 %5)
Save it as npmbin.cmd in your path, then you could run:
npmbin.cmd grunt build
Powershell
For your case, you should be able to invoke it through powershell using the invoke-expression cmdlet:
iex "$(npm bin)grunt build"
I don't have npm on me right now, but I tested with other program and it looks like it would work.
Environment Variable
Anyway, I think the previous are very complicated "solutions", while you only want to simplify your command. I was wondering if you could create a global variable, say NPMBIN
and then use it for your commands:
%NPMBIN%grunt build
To extend this you could set up a task to set it programatically for your user (or eventually the computer) using setx
, some batch like:
for /f "tokens=*" %%n in ('npm bin') do @(setx NPMBIN %%n)
Hope it helps. Regards
add a comment |
up vote
0
down vote
as they already stated in the comments, there is no native way of doing this with cmd. However there is a hack that you may use for your case (as npm bin
only returns one line):
for /F "tokens=*" %n IN ('npm bin') DO @(%ngrunt build)
or inside a batch file you have to duplicate the %
:
for /F "tokens=*" %%n IN ('npm bin') DO @(%%ngrunt build)
Alternatives
Batch
You could generate a script that receives the parameter and runs the command, something like
:: Takes the parameters and send to npm bin output
for /f "tokens=*" %%n in ('npm bin') do @(%%n%1 %2 %3 %4 %5)
Save it as npmbin.cmd in your path, then you could run:
npmbin.cmd grunt build
Powershell
For your case, you should be able to invoke it through powershell using the invoke-expression cmdlet:
iex "$(npm bin)grunt build"
I don't have npm on me right now, but I tested with other program and it looks like it would work.
Environment Variable
Anyway, I think the previous are very complicated "solutions", while you only want to simplify your command. I was wondering if you could create a global variable, say NPMBIN
and then use it for your commands:
%NPMBIN%grunt build
To extend this you could set up a task to set it programatically for your user (or eventually the computer) using setx
, some batch like:
for /f "tokens=*" %%n in ('npm bin') do @(setx NPMBIN %%n)
Hope it helps. Regards
add a comment |
up vote
0
down vote
up vote
0
down vote
as they already stated in the comments, there is no native way of doing this with cmd. However there is a hack that you may use for your case (as npm bin
only returns one line):
for /F "tokens=*" %n IN ('npm bin') DO @(%ngrunt build)
or inside a batch file you have to duplicate the %
:
for /F "tokens=*" %%n IN ('npm bin') DO @(%%ngrunt build)
Alternatives
Batch
You could generate a script that receives the parameter and runs the command, something like
:: Takes the parameters and send to npm bin output
for /f "tokens=*" %%n in ('npm bin') do @(%%n%1 %2 %3 %4 %5)
Save it as npmbin.cmd in your path, then you could run:
npmbin.cmd grunt build
Powershell
For your case, you should be able to invoke it through powershell using the invoke-expression cmdlet:
iex "$(npm bin)grunt build"
I don't have npm on me right now, but I tested with other program and it looks like it would work.
Environment Variable
Anyway, I think the previous are very complicated "solutions", while you only want to simplify your command. I was wondering if you could create a global variable, say NPMBIN
and then use it for your commands:
%NPMBIN%grunt build
To extend this you could set up a task to set it programatically for your user (or eventually the computer) using setx
, some batch like:
for /f "tokens=*" %%n in ('npm bin') do @(setx NPMBIN %%n)
Hope it helps. Regards
as they already stated in the comments, there is no native way of doing this with cmd. However there is a hack that you may use for your case (as npm bin
only returns one line):
for /F "tokens=*" %n IN ('npm bin') DO @(%ngrunt build)
or inside a batch file you have to duplicate the %
:
for /F "tokens=*" %%n IN ('npm bin') DO @(%%ngrunt build)
Alternatives
Batch
You could generate a script that receives the parameter and runs the command, something like
:: Takes the parameters and send to npm bin output
for /f "tokens=*" %%n in ('npm bin') do @(%%n%1 %2 %3 %4 %5)
Save it as npmbin.cmd in your path, then you could run:
npmbin.cmd grunt build
Powershell
For your case, you should be able to invoke it through powershell using the invoke-expression cmdlet:
iex "$(npm bin)grunt build"
I don't have npm on me right now, but I tested with other program and it looks like it would work.
Environment Variable
Anyway, I think the previous are very complicated "solutions", while you only want to simplify your command. I was wondering if you could create a global variable, say NPMBIN
and then use it for your commands:
%NPMBIN%grunt build
To extend this you could set up a task to set it programatically for your user (or eventually the computer) using setx
, some batch like:
for /f "tokens=*" %%n in ('npm bin') do @(setx NPMBIN %%n)
Hope it helps. Regards
answered Nov 19 at 19:11
Jorge Valentini
1358
1358
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1137190%2fequivalent-of-bashs-on-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
In what shell on Windows? Are you running Bash on Windows? Should work the same as bash anywhere else. If this isn't bash, then the shell you are using matters. That is, powershell certainly supports subexpressions, using the exact same syntax even.
– Zoredache
Oct 20 '16 at 23:40
Good point. I meant in
cmd.exe
.– Nick Heiner
Oct 24 '16 at 15:13
AFAIK cmd.exe has no support for sub-expressions.
– Zoredache
Oct 24 '16 at 16:54