zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <disposable1@telefonica.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: Making a script 'sourceable'
Date: Sat, 4 Sep 2004 13:07:24 +0200	[thread overview]
Message-ID: <20040904110724.GA12874@DervishD> (raw)

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> >     That given, I'm trying to do two things. First one is detecting
> > the 'sourcing' non portably, in zsh.
> It can be done if setopt NO_FUNCTION_ARG_ZERO is in effect before the
> script is sourced by comparing $0 either to $SHELL or to the name of
> the script.
    Oh, I forgot FUNCTION_ARGZERO. For scripts not intended to be
'exported' outside my system this will do, thanks a lot :)

> > thinking about now is to check the value of the option 'interactive'.
> > If it is on, chances are that we have sourced the script. Otherwise,
> > we may not. This is not perfect, though, because you can run a script
> > (interactive=off) and then source the other script within...
> If all your scripts check both the option and the state of $0 and then 
> explicitly turn off FUNCTION_ARG_ZERO, you're pretty much guaranteed to 
> catch direct sourcing the with the options and indirect sourcing with $0.

    I'll give it a try.
 
> >     The second thing is derived from the above question: since
> > checking for 'sourcery' ;) is very difficult even non portably, I've
> > thought about making my zsh scripts sourceables.
> Lloyd Z. has the way of it.
    Well, an extra fork... I don't really like that method, but... I
was thinking about writing the scripts carefully so they don't mess
with the current environment. The main problem seems to be the
environment variables and, in the case of zsh, the options (a
portable shell script won't mess with the options). But Lloyd's
solution is more reliable and the price, in modern OS's, is almost
negligible.

    Thanks for your help.

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


             reply	other threads:[~2004-09-04 11:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-04 11:07 DervishD [this message]
2004-09-04 15:44 ` Bart Schaefer
2004-09-05 13:33   ` DervishD
  -- strict thread matches above, loose matches on Subject: below --
2004-09-03 16:35 DervishD
2004-09-03 17:01 ` Lloyd Zusman
2004-09-03 22:16   ` DervishD
2004-09-03 17:20 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040904110724.GA12874@DervishD \
    --to=disposable1@telefonica.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).