Removing "\\exec" from the statement, and appending -c "\\gexec" to the psql command technically worked, but did not run the commands.
I don't know why, but \g* commands don't work from the -c option. But in this case it is not necessary
Well, the -c option states:
command must be either a command string that is completely parsable by the server (i.e., it contains no psql-specific features), or a single backslash command. Thus you cannot mix SQL and psql meta-commands within a -c option.
Thus any meta-command that interacts with server-parsed SQL is rendered useless in -c