postgresql set variable not working with command option
It's not a bug, as the psql documentation warns about this:


  -c command
  ...
  
  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.


The expansion of :'env' in -c "SELECT :'env';" is a psql-specific feature.

I would suggest that the solution is to use heredoc rather than -c:

$ psql -v env=test &lt;&lt;END_OF_SQL
select :'env';
END_OF_SQL


Output:

?column? 
----------
 test
(1 row)