I want to add a function to precmd_functions at ZSH login and avoid duplication. Since /etc/zprofile source the /etc/profile, which then source all the *.sh script under /etc/profile.d/, my solution is to add init scripts to /etc/profile.d. To keep compatible with bash, the auto sourced script new_script.sh is like:
# zsh user
if [ -n "$ZSH_VERSION" ]; then
source /etc/profile.d/new_script.zsh
# bash user
elif [ -n "$BASH_VERSION" ]; then
source /etc/profile.d/new_script.bash
fi
To here it all green, but then the new_script.zsh made a strange behaviour. It has contents like:
...
if (( $precmd_functions[(I)audit_hook] )); then
hook_exist=true
else
hook_exist=false
fi
When I manually source it after login in using zsh, it run without any problem. But when automatically sourced at login init process, it reported bad output format specification in the if (( $precmd_functions... line.
So why only login init report this error while manually source the script not?
zsh -l -xto maybe see what's going on around when the error occurs?