Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: sourcing a sh file in zsh
- X-seq: zsh-workers 26454
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: sourcing a sh file in zsh
- Date: Mon, 26 Jan 2009 15:07:13 -0800
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=GvBvLMH6p33K3n1ftrjikwvUwCmjLkBVHhn95uEtV6tXSXWMxsJrakMytba8/M2j1p+TTb2HaDHdGTMZV+SCo6hed+w8cJ/wNjGeYEeg5ikenvikQHBzClUT3lvm6IZxU2l7IICOAK0HT0M7DUdtiq2qWNSqp0hOvxlyP4UxNGw=;
- In-reply-to: <200901251341.44463.arvidjaar@xxxxxxxxx>
- Mail-followup-to: zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <BD9D2405-AD6A-4336-9C8A-85149165B6B8@xxxxxxxxx> <200901251156.04815.arvidjaar@xxxxxxxxx> <2d460de70901250225g37845bftbbf4b87f12997a7c@xxxxxxxxxxxxxx> <200901251341.44463.arvidjaar@xxxxxxxxx>
On 2009-01-25 at 13:41 +0300, Andrey Borzenkov wrote:
> I asked already - why would you want to create non-zsh function inline
> in zsh script?
Unit tests.
If I, or anybody else, is going to make changes for which bugs could
crop up far and wide if I/we make mistakes, it will have unit tests
written.
Writing those tests is much easier if you can include the tests inline.
Now, those tests could be arranged to end up in external files before
being run, the most obvious mechanism being (assuming -S for Sticky):
fn==(cat <<-\HERE
# shell bits
HERE
) && emulate -SR sh -c "source $fn"
but being purely inline would be less grotesque to read.
I see the setopt/emulate argument and I can see benefits either way. I
went with setopt just because it was what I thought of first and it
seems easiest, but that doesn't mean it's best. What I do like with the
setopt approach is that there's a way for zsh to test if this is
currently the case.
Eg, for bash/zsh portability, you could do:
if [[ -n $ZSH_VERSION && -o sticky_options ]]
since both support [[ conditional ]] and both support -o as a unary
prefix test (both using it for testing shell options).
-Phil
Messages sorted by:
Reverse Date,
Date,
Thread,
Author