I am trying to create a function that converts a time string to total minutes ie “11:22” would return 682
str_to_min(){
ARR_T=$(echo $1 | tr ":" "\n")
HOUR=${ARR_T[0]}
MINUTE=${ARR_T[1]}
let MIN=(60*$HOUR)
let MIN=($MIN+$MINUTE)
#echo total minutes $MIN
return $MIN
}
str_to_min "11:22"
but i keep getting the following error:
./find_service_to_display.sh: line 5: let: MIN=(60*11: missing )' (error token is "11"))’ (error token is “11”)
./find_service_to_display.sh: line 6: let: MIN=(11: missing
Try this:
You probably want ‘echo’ rather than ‘return’ unless you really want a return status (which acts like a program exit code).