Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How sensible is ... ?



Phil Pennock wrote:
> > #!/bin/zsh -f
> > case $context in
> >  toplevel) alias leave=exit ;;
> >  function) alias leave=return ;;
> > esac
> 
> Actually, I've just thought of [[ -o interactive ]] -- always the way.
> 
> Is this a sufficient test?  It /seems/ to work as I want ...

In this particular case, you don't need it, since return will function
like exit in a script.

I've thought of a hack which is pretty much guaranteed to work (I
think):

  foo=global
  local foo >/dev/null
  if [[ $foo = global ]]; then 
    print At top level
  else
    print Inside a function
  fi

The nasty bit is the `local foo' which prints the status of $foo if it
already exists.  I keep thinking we ought to do something about that.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author