I've been using
emulate sh -c ". $HOME/myscript.sh" and it's working so far.
However, if I'm at
~ and try to do
emulate sh -c ". myscript.sh", I get
.: no such file or directory: myscript.sh.. Why?
. builtin looks for the script passed argument in the command search path (
$PATH) if it doesn't contain a
/. This is true both in POSIX shells and in native zsh, so unsurprisingly it's true in zsh's sh emulation mode as well.
source builtin in bash and zsh is identical to
. except that no PATH lookup happens, a script name not containing a
/ is looked for in the current directory.
emulate sh -c 'source myscript.sh'
emulate sh -c '. ./myscript.sh'