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

Re: sourcing a sh file in zsh

On Jan 20,  7:48pm, Peter Stephenson wrote:
} > Combined with allowing "emulate" create a scope and run a command
} > in that scope, is there anything else you'd need?
} > 
} > PWS, any comment on how difficult it would be to extend "emulate" in
} > this way?  Would it require promoting emulate to a keyword?
} I haven't heard anything that sounds particularly difficult, although it
} obviously needs a firm grip on what's being set at what point.  I don't
} see why emulate should have to behave specially as far as syntax is
} concerned, as long as its behaviour is well defined.

My thought was that emulate behave syntactically something like "exec":

    % var="a string with spaces"
    % emulate sh print -l $var

There'd also be an option to go with -L and -R to cause the emulation
mode to become "sticky" in the wordcode for any function defined "in
the scope of" the emulate ("-X" used here as placeholder):

    % emulate -X sh function foo { print -l $@ }
    % foo "more spaces here"

It may be going too far to make emulate a syntactic element like that.
So the next best thing is if it works more like "eval":

    % emulate -X sh 'foo() { print -l $@ }'

The most frequent intended usage being

    % emulate -X sh source ~/some_bash_library.sh

which would apply the "sticky emulation" to all the functions that
might be defined by some_bash_library.sh.

Maybe the sticky-option isn't even needed, maybe it should just always
become sticky when called with a command as arguments.

There are all sorts of variants of this that I'd find acceptable.
One that might be esthetically pleasing would be using a -c option,
as if you were running the shell in question:

    % emulate ksh -c 'source ~/some_ksh_library.sh'

That's probably enough examples.

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