I get this error message for my shell script below:
./my_script.sh line 17: f1bfab2e-168a: value too great for base (error token is "168a")
data=($( jq -r '.data' data.json | tr -d '[]," ' ))
for i in "${data[@]}"; do
echo "${data[i]}"
done
(data
is made up of array elements that are a series of letters and numbers such as f1bfab2e-168a-4da7-9677-5018e5f97g0f
)
I've referenced other Stack Overflow posts that provide solutions such as variable indirection or characters getting interpreted as octal numbers but I have been unable to resolve this error.
When using variable indirection such as
data=($( jq -r '.data' data.json | tr -d '[]," ' ))
for i in "${data[@]}"; do
echo "${data[${!i}]}"
done
"${data[${!i}]}"
ends up only referencing the first array element for some reason. So if my array has two elements abc123
and bcd234
, then what gets printed is just
abc123
abc123
instead of
abc123
bcd234
.
I don't exactly understand why and what's going on there.
Additionally, I don't think that bash is interpreting any of my characters as octal numbers here so a solution for that situation does not apply to my case.
What significance does 168a
have to bash?
CodePudding user response:
The i
is already the item of the array, not the index, as you seem to believe. This should work:
for i in "${data[@]}"; do
echo "$i"
done