I'm new to bash scripting and trying to learn.
I have a variable $temp, that contains what I get from an API call, which is a long list of SHA1 hashes. I want to take what is in $temp and create an array that I can loop through and compare each entry to a string I have defined. Somehow, I can not seem to get it to work. The array I create always only contains only one element. It is like the rest of the string in $temp is being ignored.
I have tried multiple approaches, and can't get anything working the way I want it to. Here's the code snippet:
temp=$(curl --silent --request GET "https://api.pwnedpasswords.com/range/$shortendHash")
echo "Temp is: $temp"
declare -A myArr
read myArr <<<$temp
echo ${myArr[@]}
echo ${myArr[0]}
echo ${myArr[1]}
When I run this, I get a full list of hashes, when I echo $temp (line 2), something like this:
"Temp is: 002C3CADF9FC86069F09961B10E0EDEFC45:1 003BE35BD9466D19258E79C8665AFB072F6:1 0075B2ADF782F9677BDDF8CC5778900D986:8 00810352C02B145FF304FCBD5BEF4F7AA9F:1 013720F40B99D6BCF6F08BD7271523EBB49:1 01C894A55EBCB6048A745B37EC2D989F102:1 030B46D53696C8889910EE0F9EB42CEAE97:4 03126B56153F0564F4A6ED6E734604C67E8:2 043196099707FCB0C01F8C2111086A92A0B:1 0452CABBEF8438F358F0BD8089108D0910E:5 0490255B206A2C0377EBD080723BF72DDAE:2 05AD1141C41237E061460DB5CA5412C1A48:4 05C1D058E4439F8F005EFB32E7553E6AA5B:1 067AF515CC712AC4ACA012311979DBC7C9A:2 ... and so on.."
But the
echo ${myArr[@]}
echo ${myArr[0]}
echo ${myArr[1]}
returns (first value is ${myArr[@]}, second is ${myArr[0]}, and last one is an empty line, indicating that there is no value at array position 1):
002C3CADF9FC86069F09961B10E0EDEFC45:1 002C3CADF9FC86069F09961B10E0EDEFC45:1
I hope someone can help with this.
Thanks a lot in advance!