Too many open files error when trying to ssh into mac

Solution 1:

The following line in one of my bash scripts was the problem:

declare -fx $(bash -c "source ~/.local/bash.d/functions/10-git.bash; compgen -A function").

I'm not sure why it results in the error, however.