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









share|improve this question




















  • 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















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









share|improve this question




















  • 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













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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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














  • 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








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










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






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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






    share|improve this answer

























      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






      share|improve this answer























        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 19:11









        Jorge Valentini

        1358




        1358






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            QoS: MAC-Priority for clients behind a repeater

            Ивакино (Тотемский район)

            Unable to view message in Sitecore 7.2 ECM