Answer the question
In order to leave comments, you need to log in
How to put the output of a command line by line in a bash array?
I have some string. I want to split it on the delimiter " , ". Everything turns out, but I want to make each element that I broke into an array element. If you write all this into a variable/immediately into an array, you get a continuous string (and after all, separate lines were originally obtained) and the elements of the array will become words separated by spaces, which is not good. The dumb way is to write everything to a file and count it line by line, it works. But I would like to do without files. Is it possible somehow?
a='trololo oo, lalala aa, lalala''
awk '{split($0,stuff,","); for(i in stuff) { print(stuff[" i "]= stuff[i])} }'
ps it is necessary that trololo oo be the first element, not trololo - 1st, and oo - 2nd...
Answer the question
In order to leave comments, you need to log in
a='{"message":"done it","result":"1204","status":200}'
array_num=0
while read LINE; do
curl_answ_array[${array_num}]=${LINE}
let array_num=${array_num}+1
done < <(echo ${a}|grep status -m 1|tr -d '\"{}'|awk ' {split($0,stuff,","); for(i in stuff) { print(stuff[" i "]= stuff[i])} }')
a='trololo oo, lalala aa, lalala'
mapfile -t -d, strings < <(echo "$a")
echo "${strings[0]}"
echo "${strings[1]}"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question