\set naccounts 100000 * :scale

-- Should works
\setshell aid expr 1 + :naccounts

-- *Shouldn't* work.
-- \setshell :aid expr 1 + :naccounts

-- :aid should be replaced, but ::aid *shouldn't*.
\shell echo ::aid :aid selected from :naccounts accounts
DO $$ BEGIN RAISE INFO ':aid vs. ::aid'; END; $$ LANGUAGE plpgsql;
