zsh return 0 if script sourced not executed
I'm working on extending a set of shell scripts, one of the originals has a ton of functions that I'd like to use in others, however sourcing it executes it and things get all messy from there. I added this to hopefully stop it at a certain point if it's not directly executed:
Code:
if [ "$(basename $0)" != "makepkg" ]; then Does anyone have any suggestions as to other ways I can get around this? I've checked the zshbuiltins manpage to see if there is any tricky ways around it but couldn't find anything useful and Google isn't much help as soon as the word "source" is included in the search :/ Any ideas would be greatly appreciated :) |
I think you want to set the option NO_FUNCTION_ARG_ZERO:
Code:
~/tmp% cat thing.sh |
Quote:
Quote:
Could you reverse the logic? E.g. Code:
if [[ ${0:t} == makepkg ]]; then Note that you don't need to quote $variables in zsh (unless you set shwordsplit). Also, :t does the same job as basename without spawning another program. |
All times are GMT -5. The time now is 05:26 AM. |