zsh-users
 help / color / mirror / code / Atom feed
* 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

* Re: Perl replacement challenge
  1997-10-29 17:09 Perl replacement challenge ramos
@ 1997-10-29 20:20 ` TGAPE!
  0 siblings, 0 replies; 7+ messages in thread
From: TGAPE! @ 1997-10-29 20:20 UTC (permalink / raw)
  To: ramos; +Cc: zsh-users

ramos@ih4ess.ih.lucent.com wrote:
>> 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:

8><= 8><=

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

0=-ksh

Does this help?  (Note: you still need emulate ksh, and you probably
will want to change it back, but it works for me in some cases.  It
doesn't make the emulation better, but it tends to circumnavigate their
tests to see if you're running ksh.)

Ed


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

* Re: Perl replacement challenge
  1997-10-29 16:19 ramos
                   ` (2 preceding siblings ...)
  1997-10-29 17:08 ` Andrew Main
@ 1997-10-29 17:11 ` Bart Schaefer
  3 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 1997-10-29 17:11 UTC (permalink / raw)
  To: ramos, zsh-users

On Oct 29, 10:19am, ramos@ih4ess.ih.lucent.com wrote:
} Subject: Perl replacement challenge
}
} 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") }

First question:  Have you tried

	kshdot() {
	  emulate -R ksh
	  setopt localoptions
	  . $*
	}

Second question:  If zsh's ksh emulation isn't good enough, what about

	kshdot() {
	  setopt localoptions allexport
	  source =(ksh -c ". $* 1>&2; export")
	}

I'm assuming that ksh's "export" works much like zsh's; I don't have a
copy of ksh to try it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Perl replacement challenge
  1997-10-29 16:19 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
  3 siblings, 0 replies; 7+ messages in thread
From: Andrew Main @ 1997-10-29 17:08 UTC (permalink / raw)
  To: ramos; +Cc: zsh-users

ramos@ih4ess.ih.lucent.com wrote:
>	# Use "kshdot some_ksh_script" instead of ". some_ksh_script"
>
>	kshdot() { source =(ksh -c ". $* 1>&2; senv") }

How about

function kshdot {
  emulate ksh
  setopt localoptions
  . $@
}

-zefram


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

* Re: Perl replacement challenge
  1997-10-29 16:19 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
  3 siblings, 0 replies; 7+ messages in thread
From: Bruce Stephens @ 1997-10-29 16:59 UTC (permalink / raw)
  To: zsh-users

ramos@ih4ess.ih.lucent.com said:
> 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. 

What's so wacky about these scripts that zsh doesn't understand them?  If they 
work under "emulate ksh", then you could probably switch this on temporarily 
why you source them.

I also use some environment setting scripts from ksh users, but they're POSIX 
enough that zsh just works.



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

* Re: Perl replacement challenge
  1997-10-29 16:19 ramos
@ 1997-10-29 16:46 ` Peter Stephenson
  1997-10-29 16:59 ` Bruce Stephens
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 1997-10-29 16:46 UTC (permalink / raw)
  To: ramos, 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 lists exported variables directly from ksh, which quotes them
where necessary; also it unexports _ and PWD (this does not reach back
to the calling zsh of course) so they don't appear in the list.  Since
ksh doesn't put the `export' in front, you can use `allexport'; that
only lasts for the length of the function.

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.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


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

* 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

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 17:09 Perl replacement challenge ramos
1997-10-29 20:20 ` TGAPE!
  -- strict thread matches above, loose matches on Subject: below --
1997-10-29 16:19 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

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