I have a function in .zshrc
that mostly updates the PATH
:
my_function()
{
PATH=...
}
and some scripts that depend on it, e.g. my_script.sh
starts with the following lines:
my_function
# do stuff ...
I then have the following in crontab
:
00 02 * * * /path/to/my/zsh /path/to/my_script.sh
but I have noticed that, even when I run my_script.sh
as ./my_script.sh
manually (i.e. from my interactive(?) Zsh shell), I get the error:
Command not found: my_function
even though I can perfectly invoke my_function
from the terminal.
Why? I would like a solution that does not require me to add a shebang to my script (for more on this see this)
I found the following diagram. I imagine that in my case, cron launches a non-interactive, non-login shell, which is why none of the init files are run. Is that correct?
.sh
script run with a zsh interpreter? Even if you put your functions in the right place for a zsh interpreter to find them, they won't get sourced if you are using a bash interpreter to run your script..zshenv
, do you know what else is potentially missing?