Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH Wild-card : Select all variables (not the content)

Tags:

bash

shell

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..?

like image 358
yPhil Avatar asked Dec 28 '22 20:12

yPhil


1 Answers

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
like image 163
Ignacio Vazquez-Abrams Avatar answered Jan 09 '23 16:01

Ignacio Vazquez-Abrams