Can zargs run aliases?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have pip install -U aliased as pi. I want to run:



zargs ~/scripts/python/**/requirements.txt -- pi -r


Is there any way to do this?



I also tried this ugly alternative:



zargs ~/scripts/python/**/requirements.txt -- $aliases[pi] -r


But it said (eval):2: command not found: pip install -U.



I imagined zargs should be able to do exactly these kinds of stuff, since it is a zsh builtin.










share|improve this question

























    up vote
    3
    down vote

    favorite












    I have pip install -U aliased as pi. I want to run:



    zargs ~/scripts/python/**/requirements.txt -- pi -r


    Is there any way to do this?



    I also tried this ugly alternative:



    zargs ~/scripts/python/**/requirements.txt -- $aliases[pi] -r


    But it said (eval):2: command not found: pip install -U.



    I imagined zargs should be able to do exactly these kinds of stuff, since it is a zsh builtin.










    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have pip install -U aliased as pi. I want to run:



      zargs ~/scripts/python/**/requirements.txt -- pi -r


      Is there any way to do this?



      I also tried this ugly alternative:



      zargs ~/scripts/python/**/requirements.txt -- $aliases[pi] -r


      But it said (eval):2: command not found: pip install -U.



      I imagined zargs should be able to do exactly these kinds of stuff, since it is a zsh builtin.










      share|improve this question













      I have pip install -U aliased as pi. I want to run:



      zargs ~/scripts/python/**/requirements.txt -- pi -r


      Is there any way to do this?



      I also tried this ugly alternative:



      zargs ~/scripts/python/**/requirements.txt -- $aliases[pi] -r


      But it said (eval):2: command not found: pip install -U.



      I imagined zargs should be able to do exactly these kinds of stuff, since it is a zsh builtin.







      zsh xargs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 2 at 13:13









      HappyFace

      31211




      31211




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Aliases are csh's poor man's functions. The aliases are not really commands, they are more text substitutions. aliases have their use in more advanced shells that do have functions, as hacking tools for cases where functions can't be used, like in things like:



          alias forever='while true; do'


          Or



          alias fail=' echo >&2 FAIL; return 1; '


          Which wouldn't work with functions. But here, it's not one of those cases.



          alias pi='pip install -U'


          Doesn't define a pi command, it defines a pi alias. Here, as it happens, upon expansion, that ends up being turned into the start of a simple command, but aliased are not expanded in all cases where a command is expected. In particular, they are not expanded within functions like zargs here (well, they are, but at the time of the function definition, not invocation, that's were our forever or fail aliases above can be useful). And they are expanded in some contexts where not appropriate (like in pi() ...; ).



          A global alias is not a solution, global aliases are still not commands, they'll still text substitution, but expanded in even more cases.



          After a



          alias -g pi='pip install -U'


          Now, a pi word is expanded wherever it occurs. So for instance, echo pi would output pip install -U.



          Here, if you wanted to define a pi command, you would use a function:



          pi() pip install -U "$@"


          That one would be invoked by zargs.



          With your pi simple alias, you could still do:



          zargs ~/scripts/python/**/requirements.txt -- $=aliases[pi] -r


          That is, invoke $IFS-splitting on the definition of the alias. Or going a bit further:



          zargs ~/scripts/python/**/requirements.txt -- "$(@Q)$(ze)aliases[pi]" -r 


          where z does the splitting while taking into account quoting (so for instance echo "foo bar" be split into echo and "foo bar" instead of echo, "foo and bar"), e to perform expansions (like echo $(uname) expanded to echo Linux for instance), Q to remove the quotes, which would give a better approximation in a few more cases.






          share|improve this answer






















          • But isn't an alias faster than a function?
            – HappyFace
            Dec 2 at 16:24










          • @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
            – Stéphane Chazelas
            Dec 2 at 16:29










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f485483%2fcan-zargs-run-aliases%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
          1
          down vote



          accepted










          Aliases are csh's poor man's functions. The aliases are not really commands, they are more text substitutions. aliases have their use in more advanced shells that do have functions, as hacking tools for cases where functions can't be used, like in things like:



          alias forever='while true; do'


          Or



          alias fail=' echo >&2 FAIL; return 1; '


          Which wouldn't work with functions. But here, it's not one of those cases.



          alias pi='pip install -U'


          Doesn't define a pi command, it defines a pi alias. Here, as it happens, upon expansion, that ends up being turned into the start of a simple command, but aliased are not expanded in all cases where a command is expected. In particular, they are not expanded within functions like zargs here (well, they are, but at the time of the function definition, not invocation, that's were our forever or fail aliases above can be useful). And they are expanded in some contexts where not appropriate (like in pi() ...; ).



          A global alias is not a solution, global aliases are still not commands, they'll still text substitution, but expanded in even more cases.



          After a



          alias -g pi='pip install -U'


          Now, a pi word is expanded wherever it occurs. So for instance, echo pi would output pip install -U.



          Here, if you wanted to define a pi command, you would use a function:



          pi() pip install -U "$@"


          That one would be invoked by zargs.



          With your pi simple alias, you could still do:



          zargs ~/scripts/python/**/requirements.txt -- $=aliases[pi] -r


          That is, invoke $IFS-splitting on the definition of the alias. Or going a bit further:



          zargs ~/scripts/python/**/requirements.txt -- "$(@Q)$(ze)aliases[pi]" -r 


          where z does the splitting while taking into account quoting (so for instance echo "foo bar" be split into echo and "foo bar" instead of echo, "foo and bar"), e to perform expansions (like echo $(uname) expanded to echo Linux for instance), Q to remove the quotes, which would give a better approximation in a few more cases.






          share|improve this answer






















          • But isn't an alias faster than a function?
            – HappyFace
            Dec 2 at 16:24










          • @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
            – Stéphane Chazelas
            Dec 2 at 16:29














          up vote
          1
          down vote



          accepted










          Aliases are csh's poor man's functions. The aliases are not really commands, they are more text substitutions. aliases have their use in more advanced shells that do have functions, as hacking tools for cases where functions can't be used, like in things like:



          alias forever='while true; do'


          Or



          alias fail=' echo >&2 FAIL; return 1; '


          Which wouldn't work with functions. But here, it's not one of those cases.



          alias pi='pip install -U'


          Doesn't define a pi command, it defines a pi alias. Here, as it happens, upon expansion, that ends up being turned into the start of a simple command, but aliased are not expanded in all cases where a command is expected. In particular, they are not expanded within functions like zargs here (well, they are, but at the time of the function definition, not invocation, that's were our forever or fail aliases above can be useful). And they are expanded in some contexts where not appropriate (like in pi() ...; ).



          A global alias is not a solution, global aliases are still not commands, they'll still text substitution, but expanded in even more cases.



          After a



          alias -g pi='pip install -U'


          Now, a pi word is expanded wherever it occurs. So for instance, echo pi would output pip install -U.



          Here, if you wanted to define a pi command, you would use a function:



          pi() pip install -U "$@"


          That one would be invoked by zargs.



          With your pi simple alias, you could still do:



          zargs ~/scripts/python/**/requirements.txt -- $=aliases[pi] -r


          That is, invoke $IFS-splitting on the definition of the alias. Or going a bit further:



          zargs ~/scripts/python/**/requirements.txt -- "$(@Q)$(ze)aliases[pi]" -r 


          where z does the splitting while taking into account quoting (so for instance echo "foo bar" be split into echo and "foo bar" instead of echo, "foo and bar"), e to perform expansions (like echo $(uname) expanded to echo Linux for instance), Q to remove the quotes, which would give a better approximation in a few more cases.






          share|improve this answer






















          • But isn't an alias faster than a function?
            – HappyFace
            Dec 2 at 16:24










          • @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
            – Stéphane Chazelas
            Dec 2 at 16:29












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Aliases are csh's poor man's functions. The aliases are not really commands, they are more text substitutions. aliases have their use in more advanced shells that do have functions, as hacking tools for cases where functions can't be used, like in things like:



          alias forever='while true; do'


          Or



          alias fail=' echo >&2 FAIL; return 1; '


          Which wouldn't work with functions. But here, it's not one of those cases.



          alias pi='pip install -U'


          Doesn't define a pi command, it defines a pi alias. Here, as it happens, upon expansion, that ends up being turned into the start of a simple command, but aliased are not expanded in all cases where a command is expected. In particular, they are not expanded within functions like zargs here (well, they are, but at the time of the function definition, not invocation, that's were our forever or fail aliases above can be useful). And they are expanded in some contexts where not appropriate (like in pi() ...; ).



          A global alias is not a solution, global aliases are still not commands, they'll still text substitution, but expanded in even more cases.



          After a



          alias -g pi='pip install -U'


          Now, a pi word is expanded wherever it occurs. So for instance, echo pi would output pip install -U.



          Here, if you wanted to define a pi command, you would use a function:



          pi() pip install -U "$@"


          That one would be invoked by zargs.



          With your pi simple alias, you could still do:



          zargs ~/scripts/python/**/requirements.txt -- $=aliases[pi] -r


          That is, invoke $IFS-splitting on the definition of the alias. Or going a bit further:



          zargs ~/scripts/python/**/requirements.txt -- "$(@Q)$(ze)aliases[pi]" -r 


          where z does the splitting while taking into account quoting (so for instance echo "foo bar" be split into echo and "foo bar" instead of echo, "foo and bar"), e to perform expansions (like echo $(uname) expanded to echo Linux for instance), Q to remove the quotes, which would give a better approximation in a few more cases.






          share|improve this answer














          Aliases are csh's poor man's functions. The aliases are not really commands, they are more text substitutions. aliases have their use in more advanced shells that do have functions, as hacking tools for cases where functions can't be used, like in things like:



          alias forever='while true; do'


          Or



          alias fail=' echo >&2 FAIL; return 1; '


          Which wouldn't work with functions. But here, it's not one of those cases.



          alias pi='pip install -U'


          Doesn't define a pi command, it defines a pi alias. Here, as it happens, upon expansion, that ends up being turned into the start of a simple command, but aliased are not expanded in all cases where a command is expected. In particular, they are not expanded within functions like zargs here (well, they are, but at the time of the function definition, not invocation, that's were our forever or fail aliases above can be useful). And they are expanded in some contexts where not appropriate (like in pi() ...; ).



          A global alias is not a solution, global aliases are still not commands, they'll still text substitution, but expanded in even more cases.



          After a



          alias -g pi='pip install -U'


          Now, a pi word is expanded wherever it occurs. So for instance, echo pi would output pip install -U.



          Here, if you wanted to define a pi command, you would use a function:



          pi() pip install -U "$@"


          That one would be invoked by zargs.



          With your pi simple alias, you could still do:



          zargs ~/scripts/python/**/requirements.txt -- $=aliases[pi] -r


          That is, invoke $IFS-splitting on the definition of the alias. Or going a bit further:



          zargs ~/scripts/python/**/requirements.txt -- "$(@Q)$(ze)aliases[pi]" -r 


          where z does the splitting while taking into account quoting (so for instance echo "foo bar" be split into echo and "foo bar" instead of echo, "foo and bar"), e to perform expansions (like echo $(uname) expanded to echo Linux for instance), Q to remove the quotes, which would give a better approximation in a few more cases.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 2 at 15:28

























          answered Dec 2 at 15:17









          Stéphane Chazelas

          297k54561907




          297k54561907











          • But isn't an alias faster than a function?
            – HappyFace
            Dec 2 at 16:24










          • @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
            – Stéphane Chazelas
            Dec 2 at 16:29
















          • But isn't an alias faster than a function?
            – HappyFace
            Dec 2 at 16:24










          • @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
            – Stéphane Chazelas
            Dec 2 at 16:29















          But isn't an alias faster than a function?
          – HappyFace
          Dec 2 at 16:24




          But isn't an alias faster than a function?
          – HappyFace
          Dec 2 at 16:24












          @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
          – Stéphane Chazelas
          Dec 2 at 16:29




          @HappyFace, not in any significant way, they are two different features, and are both internal to the shell.
          – Stéphane Chazelas
          Dec 2 at 16:29

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485483%2fcan-zargs-run-aliases%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

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay