GPG_AGENT_PID may not be defined. Also, source gpg-agent.env before checking the PID.
If `GPG_AGENT_PID` is unset, grep will succeed if another gpg-agent is running as it will match the string `gpg-agent` where the PID was an empty string. Set a default value for grep to a value that will never match if unset, i.e. -1.