-z is a the best way.
Another options I've used is to set a variable, but it can be overridden by another variable eg
export PORT=${MY_PORT:-5432}
If the $MY_PORT variable is empty, then PORT gets set to 5432, otherwise PORT is set to the value of MY_PORT. Note the syntax include the colon and dash.