Hi,
I have written a BASH shell script (included below) which will allow me to monitor my blood pressure. The script computes the mean of 5 user input systolic, diastolic, and heart rate values.
I would like the script to then append these three values to their respective columns in a text file. How do I do this? I would like the text file to be formated so that it can be read into EXCEL. Thanks a lot.
Mike
#!/bin/bash
###########################################################################
###########################################################################
SYSTOLIC=(120 130 125 124 122)
DIASTOLIC=(90 80 75 89 73)
HEARTRATE=(60 70 80 85 75)
###########################################################################
###########################################################################
###########################################################################
###########################################################################
#Perform an initial check:
echo; echo; echo 'Performing initial check:'
#Check that SYSTOLIC has 5 elements:
if [ ${#SYSTOLIC[@]} -eq 5 ]; then
echo 'SYSTOLIC has 5 elements:' ${SYSTOLIC[@]}
else
echo; echo; echo 'ERROR: SYSTOLIC does not have 5 elements'
exit 1
fi
#Check that DIASTOLIC has 5 elements:
if [ ${#DIASTOLIC[@]} -eq 5 ]; then
echo 'DIASTOLIC has 5 elements:' ${DIASTOLIC[@]}
else
echo; echo; echo 'ERROR: DIASTOLIC does not have 5 elements'
exit 1
fi
#Check that HEARTRATE has 5 elements:
if [ ${#HEARTRATE[@]} -eq 5 ]; then
echo 'HEARTRATE has 5 elements:' ${HEARTRATE[@]}
else
echo; echo; echo 'ERROR: HEARTRATE does not have 5 elements'
exit 1
fi
echo 'Initial check complete'
###########################################################################
###########################################################################
###########################################################################
###########################################################################
#Compute the mean blood pressure and heart rate values:
echo; echo; echo 'Computing mean blood pressure and heart rate values:'
let MEAN_SYSTOLIC=(${SYSTOLIC[0]} + ${SYSTOLIC[1]} + ${SYSTOLIC[2]} + ${SYSTOLIC[3]} + ${SYSTOLIC[4]})/5
let MEAN_DIASTOLIC=(${DIASTOLIC[0]} + ${DIASTOLIC[1]} + ${DIASTOLIC[2]} + ${DIASTOLIC[3]} + ${DIASTOLIC[4]})/5
let MEAN_HEARTRATE=(${HEARTRATE[0]} + ${HEARTRATE[1]} + ${HEARTRATE[2]} + ${HEARTRATE[3]} + ${HEARTRATE[4]})/5
echo 'Mean Systolic:' $MEAN_SYSTOLIC
echo 'Mean Diastolic:' $MEAN_DIASTOLIC
echo 'Mean Heartrate:' $MEAN_HEARTRATE
###########################################################################
###########################################################################