Check if a function exists from a bash script
bash, function
Solution
if type __git_ps1 | grep -q '^function$' 2>/dev/null; then
PS1=whatever
fi
Problem
How can I determine if a function is already defined in a bash script? I am trying to make my .bash_login script portable between systems, so I want to add logic to only call a function if it exists. I want to add `__git_ps1()` to `PS1` only if that function exists on that system. This function normally defined in `git-completion.bash` which comes with git source, or by one of the bash completion scripts that ports/apt installs.