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

RE: Lukasz Stelmach: question about functions in zsh



 
> Greetings!!!
> 
> First of all, I have searched the documentation and I haven't found
> the answer so I write to you.
> 
> Is there any way in zsh to make a function declared with "function
> name() {..." syntax a global one? That is exported to environment
> of child processes of zsh which means also other instances of zsh.
> I would like to define a function in /etc/zlogin or zprofile (a *login*
> scrpit) and not in zshrc and make it defined for all subprocesses.
> 

There is no way. The problem is, environment is just a list of flat
var=value string. There is no way to mark "var" as being a function as
opposed to plain variable (the same problem with "exporting" arrays BTW ...)
Shells that do support it (I guess bash, anyone else?) introduce a hack -
they parse environment and if a value _looks_ like a function definition
they basically eval it.

First, it is a hack. It prevents legitimate variable assignment. Second, it
opens up the whole new can of worms w.r.t. security ... functions take
precedence over external commands so consider a hacker redefining /bin/grep
and calling suid program ... and there is no way to easily filter such
function definition as opposed to well known variables like LD_LIBRARY_PATH
& co.

Could you show the situation when you do need exporting functions? Frankly
speaking I cannot think of a case when it is needed (and cannot be solved
just as easily in other way).

-andrey



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