I would like to combine default assignment, as seen here, with conversion to lowercase, as seen here.
This is what I'm working with:
bash-3.2$ export MY_ENV_VAR=FaLsE
bash-3.2$ : "${MY_ENV_VAR:=false}"
bash-3.2$ echo $MY_ENV_VAR
FaLsE
I would like to set the value of MY_ENV_VAR
to lowercase in a single statement since I have 20+ lines of code grabbing values of environment variables and I'd rather not add 20+ additional lines to do the conversion by itself.
I've tried a few things, like:
bash-3.2$ : "${MY_ENV_VAR:=false,,}"
bash-3.2$ echo $MY_ENV_VAR
FaLsE
That method seems like it would work if I had Bash 4 but I'm on 3.2.
I've also tried:
bash-3.2$ myval=$(: "${MY_ENV_VAR:=false}" | tr '[:upper:]' '[:lower:]')
bash-3.2$ echo $myval
bash-3.2$
And:
bash-3.2$ myval=$(: echo "${MY_ENV_VAR:=false}" | tr '[:upper:]' '[:lower:]')
bash-3.2$ echo $myval
bash-3.2$
Which I didn't expect to work but I don't understand the default assignment enough to know how that would be used to feed the conversion to lowercase. I find certain features of Bash difficult to understand.