i want to append the variables values inside each condition into array as per the sequence i.e here first 60s then 59.8S at last 30.8N.I want to add the elements By my code only the last 4 elements are getting appended in array.
#!/bin/bash
for i in $(seq -60 1 30);do
nextint=$((i+1))
sum=$((i+nextint))
mid=`echo "$sum / 2" | bc -l`
sum=`echo $i + $mid | bc`
topmid=`echo "$sum / 2" | bc -l`
sum=`echo $mid + $nextint | bc`
bottommid=`echo "$sum / 2" | bc -l`
k=0.0
#printf "$i%.*f\n$topmid%.*f\n$mid%.*f\n$bottommid%.*f\n"
# "$topmid $mid $bottommid"
#printf "%.*f\n" $i $topmid $mid $botttommid
n='N'
s='S'
array=()
if (( $(echo "$i == $k" | bc -l) )); then
i=$( printf "%.f\n" "$i")
topmid=$(printf "%.1f\n" "$topmid")
mid=$(printf "%.1f\n" "$mid")
bottommid=$( printf "%.1f\n" "$bottommid")
topmid=$topmid$n
mid=$mid$n
bottommid=$bottommid$n
echo "$i"
echo "$topmid"
echo "$mid"
echo "$bottommid"
array+=("$i")
array+=("$topmid")
array+=("$mid")
array+=("$bottommid")
# echo "${array[@]}"
#fi
#done
elif (( $( echo "$i > $k" |bc -l ) ))
#n='N'
then
i=$( printf "%.f\n" "$i")
topmid=$(printf "%.1f\n" "$topmid")
mid=$(printf "%.1f\n" "$mid")
bottommid=$( printf "%.1f\n" "$bottommid")
i=$i$n
topmid=$topmid$n
mid=$mid$n
bottommid=$bottommid$n
echo "$i"
# eco "${array[@]}"
echo "$topmid"
echo "$mid"
echo "$bottommid"
array+=("$i")
array+=("$topmid")
array+=("$mid")
array+=("$bottommid")
else
#s='S'
<<com
printf "%.f\n" "$i"
printf "%.1f\n" "$topmid"
printf "%.1f\n" "$mid"
printf "%.1f\n" "$bottommid"
com
i=$( printf "%.f\n" "$i")
topmid=$(printf "%.1f\n" "$topmid")
mid=$(printf "%.1f\n" "$mid")
bottommid=$( printf "%.1f\n" "$bottommid")
i=$(echo $i$s| sed 's/-//g')
topmid=$(echo $topmid$s | sed 's/-//g')
mid=$(echo $mid$s | sed 's/-//g')
bottommid=$(echo $bottommid$s | sed 's/-//g')
echo "$i"
echo "$topmid"
echo "$mid"
echo "$bottommid"
array+=(" $i")
array+=(" $topmid")
array+=(" $mid")
array+=("$bottommid")
fi
done
echo "${array[*]}"
echo "${#array[@]}"
output is --- 60S 59.8S 59.5S 59.2S 59S 58.8S 58.5S 58.2S 58S ..... 28.8N 29N 29.2N 29.5N 29.8N 30N 30.2N 30.5N 30.8N 30N 30.2N 30.5N 30.8N 4
I want array to whole variables values as elements in sequence 60N 59.8N ....... 30N 30.2N 30.5N 30.8N
TIA.** I want array to whole variables values as elements in sequence 60N 59.8N ....... 30N 30.2N 30.5N 30.8N **
Aucun commentaire:
Enregistrer un commentaire