zsh-users
 help / color / mirror / code / Atom feed
* Redirecting variable fds
@ 1998-12-10 21:52 Phil Pennock
  1998-12-10 22:45 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 1998-12-10 21:52 UTC (permalink / raw)
  To: Zsh Users

Okay, I'm stumped.  I'm trying to write a function which has as one of
its arguments a file-descriptor, which should be redirected to another
arg.  My attempt is:
function bar {
	DEBUGMEM_INFOFD=$1 LD_PRELOAD=./bar.so $argv[3,-1] $1>$2
}
bar 5 test.out some-command and-an-arg

Unfortunately, somewhere in parsing, the ``$1>$2'' bit expands out to
become ``5 > test.out'' which adds an extra arg and redirects stdout.

By quick-hack was to just shove it onto the input buffer:
function bar {
	print -z DEBUGMEM_INFOFD=$1 LD_PRELOAD=./bar.so $argv[3,-1] "$1>$2"
}
and then press return.  This is not exactly optimal.  What am I doing
wrong?  Is there something I'm missing or is this the best solution?

Thanks,
-- 
--> Phil Pennock ; GAT d- s+:+ a22 C++(++++) UL++++/I+++/S+++/H+ P++@ L+++
E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++ DI+ D+
G+ e+ h* r y?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Redirecting variable fds
  1998-12-10 21:52 Redirecting variable fds Phil Pennock
@ 1998-12-10 22:45 ` Stefan Monnier
  1998-12-11  8:05   ` Phil Pennock
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 1998-12-10 22:45 UTC (permalink / raw)
  To: zsh-users

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

>>>>> "Phil" == Phil Pennock <phil@athenaeum.demon.co.uk> writes:
> function bar {
> 	DEBUGMEM_INFOFD=$1 LD_PRELOAD=./bar.so $argv[3,-1] $1>$2
> }

The parsing is done before the parameter expansion so you're screwed.
But there's a workaround, using eval:

	DEBUGMEM_INFOFD=$1 LD_PRELOAD=./bar.so eval $argv[3,-1] "$1>$2"

It's not quite correct in that the content of $argv[3,-1] should be escaped
to prevent its evaluation (à la "$@"), but my zsh expertise is lacking here.


	Stefan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Redirecting variable fds
  1998-12-10 22:45 ` Stefan Monnier
@ 1998-12-11  8:05   ` Phil Pennock
  0 siblings, 0 replies; 3+ messages in thread
From: Phil Pennock @ 1998-12-11  8:05 UTC (permalink / raw)
  To: zsh-users

I may have stumbled across a bug.  I think the zsh-developers list might
be getting sick of my bug reports.

Typing away merrily, Stefan Monnier produced the immortal words:
> The parsing is done before the parameter expansion so you're screwed.
> But there's a workaround, using eval:
function bar {
> 	DEBUGMEM_INFOFD=$1 LD_PRELOAD=./bar.so eval $argv[3,-1] "$1>$2"
}
> It's not quite correct in that the content of $argv[3,-1] should be escaped
> to prevent its evaluation ( la "$@"), but my zsh expertise is lacking here.

Ah, thanks.

By the "$@" bit, it looks as though you're trying for "${(@)argv[3,-1}"
which doesn't on its own stop globbing.  I've handled that by changing
the 'eval ' for 'eval noglob '.  So now quoted args behave as expected
and unquoted ones are expanded at function-call time.

The problem is that DEBUGMEM_INFO and LD_PRELOAD don't actually make it
into the environment.  Using 'env' as the command passed through, I can
see quite plainly that they aren't there.  But using env to place the
values into the environment works:
function bar {
  eval noglob env DEBUGMEM_INFOFD=$1 LD_PRELOAD=./bar.so "${(@)argv[3,-1]} "$1>$2"
}

Trying this:
% FOO=x eval sh -c 'echo $FOO'
and then without the eval, it seems the eval loses the auto-export
functionality, in both 3.0.5 and 3.1.5.  It doesn't appear to be
documented though.

Bug?
-- 
--> Phil Pennock ; GAT d- s+:+ a22 C++(++++) UL++++/I+++/S+++/H+ P++@ L+++
E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++ DI+ D+
G+ e+ h* r y?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-12-11  8:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-10 21:52 Redirecting variable fds Phil Pennock
1998-12-10 22:45 ` Stefan Monnier
1998-12-11  8:05   ` Phil Pennock

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