I’m detecting the variable’s names from a code file and I want to save them in an array ONLY if I haven’t done that already with the same variable name
Suppose this is the file I’m getting the variable names from:
echo $var1; echo $var2; echo $var1;
I would like to get an array like ($var1 $var2) rather than ($var1 $var2 $var1)
How do I check if the variable name already exists and how do I add that to a bash array?
If your bash is recent enough (version 4), you can use its associative arrays: