Shell错误:值对于基本值太大(错误标记为“168a”)

myzjeezk  于 2022-12-04  发布在  Shell
关注(0)|答案(1)|浏览(96)

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 abc123abc123 instead of abc123bcd234 . 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?

cgfeq70w

cgfeq70w1#

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

相关问题