I have a bunch of variables that I want to check, and if they contain the value "None" then I want to empty them.
var1=(check for some value, sometimes it returns "none")
var2=(check for some value, sometimes it returns "none")
var3=(check for some value, sometimes it returns "none")
someBizzareName=(check for some value, sometimes it returns "none")
if [[ "${var1}" == "None" ]] ; then
var1=""
fi
if [[ "${var2}" == "None" ]] ; then
var2=""
fi
And this is all working fine and dandy, only since I have a lot of varN, I will end up with a ton of if [[ "${varN}" == "None" ]]
and I have to know their names ; so I was wondering, since it's in BASH very nature to search and match everything, if there is a wild-card for variables, inside a for loop, that will match all vars, something like ${*}
(I tried that, does'nt work) ? I have done all kinds of searches but always find something about matching variable content, not the var itself..?
All, no. But you can match a pattern (but not *
).
$ echo "${!B*}"
BASH BASHOPTS BASHPID BASH_ALIASES BASH_ARGC BASH_ARGV BASH_CMDS BASH_COMMAND BASH_LINENO BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With