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

Re: sourcing a sh file in zsh



On ÐÑÑÐÐÑÐ 16 ÑÐÐÐÑÑ 2009 18:56:15 Bart Schaefer wrote:
> On Jan 16,  2:53pm, Evert Rol wrote:
> }
> } How do I source a .sh file in zsh? It works fine in bash or sh, but
> } gives an error when source in zsh.
>
> You'll probably need to do something like
>
>   emulate sh
>   source bla.sh
>
> That leaves the problem of getting back to your original zsh settings
> after the script is done.  Depending on what the script is supposed
> to accomplish, you might be able to wrap that in a shell function:
>
>   sh_source() {
>     emulate -L sh
>     source "$@"
>   }
>
> That won't work if the script wants to declare variables with typeset
> and have them remain set after it finishes.
>

I finally resorted to

# Poor man replacement for emulate -L
typeset -A __opts
__opts=(${(kv)options[*]})
emulate -R sh

for profile_func in /etc/profile.d/*.sh
do
        source $profile_func
done

options=(${(kv)__opts[*]})
unset profile_func __opts

Given that most distributions have equivalence of /etc/profile.d, having 
simple zsh way to do it (without scoping issues) would be nice.

Attachment: signature.asc
Description: This is a digitally signed message part.



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