> I suggest to reuse pgbench expression engine, developed by Haas Robert:-)
Not a bad idea (though I'm sure there are other reasonable options, too).
I checked the pgbench code - and I think it can work well - just add logical operators and compare operators.
Don't need to create more complex language there.
> Generating a error message with ${foo:?} is nice, but what psql need is just > a way to test whether a variable is defined or not.
I'm not saying we should slavishly follow bash, but don't confuse what you need with what other people need. bash (well, sh, really) grew that syntax for a reason, and it may be more than "there was this one guy back in the seventies who wanted it, and ...".