The best way to "return" data from a shell script function is to have that function send the data to standard output, rather than using the bash return
statement, because the return code which is sent back by the return
statement is a relatively small integer which shows success or failure. Indeed, you show that you expect the result from your function to come via standard output when you say:
echo `get_time_diff $unit`
The problem is that your function doesn't send its output to standard output; it tries to return that value via the return
statement. Instead of this:
and instead of
return `expr $raw_time / 60`
expr $raw_time / 60
And so on.
Hope this helps.