* xargs with functions
@ 2014-11-17 18:24 Ray Andrews
2014-11-17 18:40 ` Axel Beckert
0 siblings, 1 reply; 3+ messages in thread
From: Ray Andrews @ 2014-11-17 18:24 UTC (permalink / raw)
To: zsh-users
Is there some way to throw one's entire setup to xargs?
If I want to use a shell function with xargs I hafta do this:
$ls * | xargs ./test
Where 'test' contains:
# re-source my functions
for aa in /aWorking/Zsh/Source/*; do source $aa; done
#call my 'l' function.
l ,s "$@"
Is there a way to pass the functions forward every time automatically,
so that I can:
ls * | xargs l ,s
Or maybe some other solution? It seems clumsy. I understand that subshells
receive the environment, but not functions, why is that? Perhaps what's
needed is some way to make the subshell run .zshrc automatically? Or am
I barking up the wrong tree as usual?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xargs with functions
2014-11-17 18:24 xargs with functions Ray Andrews
@ 2014-11-17 18:40 ` Axel Beckert
2014-11-17 20:31 ` Ray Andrews
0 siblings, 1 reply; 3+ messages in thread
From: Axel Beckert @ 2014-11-17 18:40 UTC (permalink / raw)
To: zsh-users
Hi Ray,
On Mon, Nov 17, 2014 at 10:24:42AM -0800, Ray Andrews wrote:
> Is there a way to pass the functions forward every time automatically,
> so that I can:
>
> ls * | xargs l ,s
xargs is not from zsh but a binary (/usr/bin/xargs in my case) which
is called. And that binary likely calls 'exec "$@"' and not 'exec
$SHELL -c "$@"'
But zsh's zargs seems to support functions (but not aliases). Try this:
% autoload -U zargs
% zargs -- * -- l ,s
HTH
Kind regards, Axel
--
/~\ Plain Text Ribbon Campaign | Axel Beckert
\ / Say No to HTML in E-Mail and News | abe@deuxchevaux.org (Mail)
X See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber)
/ \ I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xargs with functions
2014-11-17 18:40 ` Axel Beckert
@ 2014-11-17 20:31 ` Ray Andrews
0 siblings, 0 replies; 3+ messages in thread
From: Ray Andrews @ 2014-11-17 20:31 UTC (permalink / raw)
To: zsh-users
On 11/17/2014 10:40 AM, Axel Beckert wrote:
Axel,
But zsh's zargs seems to support functions (but not aliases). Try
this: % autoload -U zargs % zargs -- * -- l ,s
Not too shabby! This worked:
$zargs -- `ls -1` -- l ,s
'piped' output of 'ls -1' to my function 'l'.
But this is what I've done previously:
$l ,s `ls -1`
... which is more compact. Is there any reason to prefer zargs? Perhaps
it can swallow
more complex input?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-11-17 20:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-17 18:24 xargs with functions Ray Andrews
2014-11-17 18:40 ` Axel Beckert
2014-11-17 20:31 ` Ray Andrews
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).