zsh-users
 help / color / mirror / code / Atom feed
* Perl replacement challenge
@ 1997-10-29 16:19 ramos
  1997-10-29 16:46 ` Peter Stephenson
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: ramos @ 1997-10-29 16:19 UTC (permalink / raw)
  To: zsh-users


hello,

I work in an environment surrounded by KSH users (hey does
this qualify as a "hostile work environment"??). That includes
the system administrators and tool developers, so it is not
surprising there are many scripts in the system which must be
"dotted" into ksh to do something non-trivial and dynamically
setup environment variables as a result.

I have a very simple and effective solution:

	# Use "kshdot some_ksh_script" instead of ". some_ksh_script"

	kshdot() { source =(ksh -c ". $* 1>&2; senv") }

Where 'senv' is the following Perl script:

	#!/usr/local/bin/perl

	# Fixup the output from 'env' so it can be sourced by zsh
	 
	foreach $ev (keys %ENV) {
	  next if $ev eq "_" || $ev eq "PWD";
	 
	  print "export $ev=";
	 
	  $val = $ENV{$ev};
	  $val =~ s/'/'"'"'/g;
	 
	  print "'$val'\n";
	}
 
Obviously, I'm not happy with having to invoke Perl everytime I
need to source a system script. But since it works, I've left it
as is for several months.

I would appreciate hearing suggestions on how to get rid of Perl,
or other ideas you have for dealing with the root problem (Note:
I don't like to use "emulate -R ksh" in my interactive shells,
it disables too many nice zsh features).


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Perl replacement challenge
@ 1997-10-29 17:09 ramos
  1997-10-29 20:20 ` TGAPE!
  0 siblings, 1 reply; 7+ messages in thread
From: ramos @ 1997-10-29 17:09 UTC (permalink / raw)
  To: zsh-users


> From pws@hydra.ifh.de  Wed Oct 29 10:47:20 1997
> X-Perlmail-1: 0 junkmail pattern matches
> Subject: Re: Perl replacement challenge 
> To: ramos@ih4ess.ih.lucent.com, zsh-users@math.gatech.edu (Zsh users list)
> 
> ramos@ih4ess.ih.lucent.com wrote:
> > I have a very simple and effective solution:
> > 
> > 	# Use "kshdot some_ksh_script" instead of ". some_ksh_script"
> > 
> > 	kshdot() { source =(ksh -c ". $* 1>&2; senv") }
> > 
> > Where 'senv' is the following Perl script:
> > ...
> 
> As a minimal modification which omits the Perl script, how about
> 
> kshdot() { 
>   setopt allexport localoptions
>   source =(ksh -c ". $* 1>&2; typeset +x _ PWD; typeset -x")
> }
> 

This almost works! But the 'typeset -x' runs inside ksh (which, in fact,
it has to), which means the quoting syntax is different.

e.g. If a variable contains control characters, ksh would print:

FOO=$'\n\n\a\n'

And that's not parsed correctly by zsh, even with "emulate ksh" on.
That example, by the way, works fine with my Perl solution.

Any other ideas???

I was wanting to rewrite the Perl script as a zsh function, but I can't
find a "search and replace" builtin in zsh to do the quoting.

e.g.

senv()   { .... this is hard to write ... }
kshdot() { source =(ksh -c ". $* 1>&2" | senv) }

> 
> But remember you can make emulate local to a function.  You might get
> away with something like
> 
> kshdot() { emulate ksh; setopt localoptions; . $*; }
> 
> at least for some of the scripts.

Yup, works for some scripts. But some of them go out of their way to
try to make sure you're really running an honest ksh.

Thanks for your time,

--
Alex Ramos
atramos@lucent.com



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

end of thread, other threads:[~1997-10-30  1:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-29 16:19 Perl replacement challenge ramos
1997-10-29 16:46 ` Peter Stephenson
1997-10-29 16:59 ` Bruce Stephens
1997-10-29 17:08 ` Andrew Main
1997-10-29 17:11 ` Bart Schaefer
1997-10-29 17:09 ramos
1997-10-29 20:20 ` TGAPE!

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