I've found the answer to this question. When calling from the shell script, its in the shell script itself that the escaping must be done. So instead of the above i should do the calling like this :
psql $PSQL_LOGIN -V SERVER="'$SERVER'"
that is double quote and single quote. Then the sql file can be done the same way as in Oracle :
select 'wget' || :SERVER '.example.com?geoX='|| id1 || ' etc