alternative to readarray, because it does not work on mac os x

后端 未结 7 1997
挽巷
挽巷 2021-01-17 16:55

I have a varsValues.txt file

cat varsValues.txt
aa=13.7
something=20.6
countries=205
world=1
languages=2014
people=7.2
oceans=3.4

And I wou

7条回答
  •  清酒与你
    2021-01-17 17:17

    Here's the awk version. Note that NPars is not hardcoded.

    vars=($(awk -F= '{print $1}' varsValues.txt))
    values=($(awk -F= '{print $2}' varsValues.txt))
    
    Npars=${#vars[@]}
    
    for ((i=0; i<$Npars; i++)); do
        eval ${vars[$i]}=${values[$i]}
    done
    
    echo $people
    

提交回复
热议问题