I have an array of values coming from bash which i just want to check if there are numbers or not in it. It can contain -, + numbers and spaces at the start or end since bash is evaluating this as sting.
Since every number is represented with , at the end i added (,) to the regex.
Basically i want to check if element is a number or not.
The $val look like these.
[ [ -0.13450142741203308, -0.3073260486125946, -0.15199440717697144, -0.06535257399082184, 0.02075939252972603, 0.03708624839782715, 0.04876817390322685 ] ,[ 0.10357733070850372, 0.048686813563108444, -0.1413831114768982, -0.11497996747493744, -0.08910851925611496, -0.04536910727620125, 0.06921301782131195, 0.02547631226480007 ] ]
This is my code which looks at each value and evaluates each. However it doesn't seem to catch the cases.
re='^[[:space:]][+-]?[0-9]+([.][0-9]+)?(,)[[:space:]]$'
for j in ${val[*]}
do
if ! [[ "$j" =~ $re ]] ; then
echo "Error: Not a number: $j"
fi
done
Also it needs to ignore cases which throw [ or ] or ],.
Any ideas how to correct this ? Thanks for the help.
$val?,0.04876817390322685 ] ,[