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

Re: Portably checking for shell level



    Hi Bart :)

 * Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> dixit:
> >     I have a shell script that cannot be sourced, because it must be
> > run in a clean environment. Under zsh I achieve this using 'emulate
> > -L zsh', or just by checking '$SHLVL' if the script won't run just by
> > defaulting the ZSH options. The problem is: how to do this portably?
> Try examining the value of "$-".  That's not foolproof, but at least it
> can tell you whether someone is "."-ing your script into an interactive
> shell.

    But the problem is that, in the better case, that only tells me
if the '-i' option was used, and SUS doesn't specify options to the
shell binary. I don't know how to otherwise use '$-' to avoid
sourcing. I'm afraid there is no portable way of doing this :(

    Thanks for the help, Bart :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



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