79090462

Date: 2024-10-15 14:46:49
Score: 0.5
Natty:
Report link

What you can try to use a while loop to read each line into an array

#!/bin/sh

cmd=$(curl -s https://jsonplaceholder.typicode.com/todos)
echo "$cmd" > Data.json

jq -r '.[] | .title' Data.json > title.txt


myArray=()

# Read each line
while IFS= read -r line; do
    myArray+=("$line")
done < title.txt

for (( i = 0 ; i < 20 ; i++ )); do
  echo "Array[$i]=\"${myArray[$i]}\""
done
Reasons:
  • Has code block (-0.5):
  • Starts with a question (0.5): What you can
  • Low reputation (0.5):
Posted by: Shelton Liu