I have written a function which checks whether one or more variables passed as arguments are empty (got the idea from here)
Here is what the script looks like:
#!/bin/bash
is_variable_defined?() {
for VAR in "$@"; do
: "${!VAR? "ERROR: $VAR is undefined."}"
done
}
TEST='a'
is_variable_defined? TEST TEST2
And here is the output:
/path/to/script.sh: line 4: !VAR: ERROR: TEST2 is undefined.
However what I would like to output is:
TEST2 is undefined
I have tried tweaking the : "${!VAR? "ERROR: $VAR is undefined."}"
line but whatever I do it breaks.
Does anybody know what to modify in the script to get the output I want?