I have to execute a function which has to test if a variable has been correctly defined in Bash and must use its associated value.
For instance, these variables are initialized at the top of the script.
#!/bin/bash
var1_ID=0x04
var2_ID=0x05
var3_ID=0x06
var4_ID=0x09
I would like to call the script named test as follows:
./test var1
The current implemented function is:
function Get()
{
if [ $1"_ID" != "" ]; then
echo "here"
echo $(($1_ID))
else
exit 0
fi
}
I don't understand why I obtain here
even if I enter ./test toto
or something else.
Do I need to use a specific command, such as grep
?