Manipulating an array (printed by php-cli) in shell script

前端 未结 3 1618
情深已故
情深已故 2021-01-23 14:54

I am a newbie with shell scripts and I learnt a lot today. This is an extension to this question Assigning values printed by PHP CLI to shell variables

I got the solutio

3条回答
  •  感情败类
    2021-01-23 15:42

    With bash4, you can use mapfile to populate an array and process substitution to feed it:

    mapfile -t array < <( your_command )
    

    Then you can go through the array with:

    for line in "${array[@]}"
    

    Or use indices:

    for i in "${#array[@]}"
    do
       : use "${array[i]}"
    done
    

提交回复
热议问题