Can zargs run aliases?
Clash 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.
zsh xargs
add a comment |
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.
zsh xargs
add a comment |
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.
zsh xargs
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
zsh xargs
asked Dec 2 at 13:13
HappyFace
31211
31211
add a comment |
add a comment |
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. alias
es 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.
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
add a comment |
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. alias
es 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.
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
add a comment |
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. alias
es 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.
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
add a comment |
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. alias
es 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.
Aliases are csh
's poor man's functions. The aliases are not really commands, they are more text substitutions. alias
es 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.
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
add a comment |
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
add a comment |
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.
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%2funix.stackexchange.com%2fquestions%2f485483%2fcan-zargs-run-aliases%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