linux - add entries to an array in bash -
in bash i'm trying create array , run through loop number of times (determined user of file) , add choice array predetermined number of times. trade data, example, choose 2 factors. program asks me input factor want, , put in open (open price of day), bid added array arr , question asked again. put in close (close price of day) close added array, , in end arr = open close that. run code , question: "how many factors check total: "
runs on , on again , never leave loop , never appears inputs being put array. mistake here appreciated. thanks.
factor="" total=0 declare -a arr read -p "how many factors check total: " -e -i "$total" total (( x=1; x=total; x++ )) read -p "enter factor list: " -e -i "$factor" factor arr+=(${arr[@]} "$factor") done echo ${arr[@]}
you got correct on array append. remember +=
operator doesn't need full reference array again on rhs. e.g. just
arr+=($factor)
would suffice append $factor
@ end of array variable arr
.
modify script little bit this:
factor="" total=0 declare -a arr read -p "how many factors check total: " -e -i "$total" total (( x=1; x<=total; x++ )) read -p "enter factor list: " -e -i "$factor" factor arr+=($factor) done echo ${arr[@]}
Comments
Post a Comment