Do you really care whether CPIC_MAX_CONV is an environment variable versus just 'it is a variable that might be an environment variable'? Most likely, you won't, not least because if it is a variable but not an environment variable, any script you run won't see the value (but if you insist on using aliases and functions, then it might matter, but still probably won't).
It appears, then, that you are trying to test whether CPIC_MAX_CONV is set to a non-empty value. There are multiple easy ways to do that — and then there's the way you've tried.
: ${CPIC_MAX_CONV:=500}
This ensures that CPIC_MAX_CONV is set to a non-empty value; it uses 500 if there previously wasn't a value set. The :
(colon) command evaluates its arguments and reports success. You can arrange to export the variable after it is created if you want to with export CPIC_MAX_CONV
.
If you must have the variable set (there is no suitable default), then you use:
: ${CPIC_MAX_CONV:?}
or
: ${CPIC_MAX_CONV:?'The CPIC_MAX_CONV variable is not set but must be set'}
The difference is that you can use the default message ('CPIC_MAX_CONV: parameter null or not set') or specify your own.
If you're only going to use the value once, you can do an 'on the fly' substitution in a command with:
cpic_command -c ${CPIC_MAX_CONV:-500} ...
This does not create the variable if it does not exist, unlike the :=
notation which does.
In all these notations, I've been using a colon as part of the operation. That enforces 'null or not set'; you can omit the colon, but that allows an empty string as a valid value, which is probably not what you want. Note that a string consisting of just a blank is 'not empty'; if you need to validate that you've got a non-empty string, you have to work a little harder.
I'm not dissecting your misuse of the [[
command; gniourf_gniourf has provided an excellent deconstruction of that, but overlooked the simpler notations available to do what seems to be the job.