Add variable value in single quoted string. Expand variable within single quotes
Try this:
-- This will concatenate the values:
\set myvariable '/var/lib/pgsql95/' :myvariable '/pg_tblspc'
-- This will expand the variable single-quoted:
CREATE TABLESPACE aspire_data OWNER aspireapp LOCATION :'myvariable'
Alternate solution:
-- Single quote is escaped and concatenated to the front and end of string
\set myvariable '''' /var/lib/pgsql95/:variable/pg_tblspc/data ''''
CREATE TABLESPACE aspire_data OWNER aspireapp LOCATION :myvariable
Peter's solution (and mine) may not work depending on your psql client version.
See SQL Interpolation section in the PostgreSQL documentation for your psql client version
If nothing works, and you are able to just pass in the variable from the command line with single quotes already around it, that may work too.