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

Re: sourcing a sh file in zsh

On Jan 25,  9:26pm, Andrey Borzenkov wrote:
} Hmm ... not convinced by this example but I realize now that if sticky 
} emulation is going to be implemented, it could be useful to define 
} sticky *zsh* function in zsh script.
} I still believe using option is the most simple and straightforward way 
} to do it.

I have a couple of quibbles with doing it with a setopt.

The first is one I already mentioned:
> It's potential can of worms along the lines of ALL_EXPORT, in that
> one can end up accidentally applying a specific option context to a
> function definition where one didn't (or shouldn't) mean to do so.

It's also unclear (to me) what to do with that setopt when one later
encounters "emulate -R".

I still think I'd rather that this be a property of "emulate ... -c"
rather than an independent setopt.

Some remars on your examples ...

} For external script library (which is unaware of zsh in any 
} case) it is simple
}   emulate sh -c "setopt sticky_emulation; source /my/shell/library.sh"

This doesn't work, does it?  "emulate sh -c ..." does not imply a full
setopts reset at the end of the eval, only a reset of the emulation
mode.  Also, are you implying that "emulate sh" would implictly unset
that setopt, requiring that it be re-asserted inside the eval?

} and zsh script can obviously do
} 	setopt sticky_emulation
} 	function zsh_func {
} 		...
} 	}
} 	unsetopt sticky_emulation

The trouble with this is that it's not obvious what emulation is being
made sticky.  In the same way that someone using zsh in "native mode"
might want to source a bash script, someone using zsh linked as sh may
want to source a zsh script.  The script author is either going to have
to explicitly call "emulate zsh -c ..." as in your first example, or
end up writing 

    local emu=$(emulation)
    [[ $emu != zsh ]] && emulate zsh 
    { setop sticky_emulation
    } always {
      unsetopt sticky_emulation
      emulate $emu

It just seems so much cleaner to wrap it all up in "emulate" in the
first place.

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