I have the below text, as the output of some command myscript.sh;
[
"string-1",
"string-2"
]
I have stored the output to some variable like below:
myarray=$(myscript.sh)
Now, I would like to echo value not present if the string string-3 is not present in the array, something like the code below;
value="string-3"
if [[ ! " ${myarray[*]} " =~ " ${value} " ]]; then
echo "value not present"
fi
This code will output value not present even if the value is present. What can be done to fix this issue?
myarrayis not an array. It is a scalar holding the complete output of your script.array like variable. So what do you think?