understand the function to execute

Gurus,

Can you please tell me why this script is executing but i am getting no result...also can you tell me what is this gettime() doing?

in a script i wrote this hour.SH
--------------------------
gettime() {
date '+%H' | {
read hour
TIME=${hour}
}
}
:
----------------------
when i do ./hour.SH ...i get no result

:eek::rolleyes::confused::o:b::D;):p:mad::slight_smile:

Where are you calling this function and where are you printing TIME.
I get the result when I do this...

gettime() {
date '+%H' | {
read hour
TIME=${hour}
}
}

gettime
echo $TIME

ksh works, bash and bsh no. Why ? ksh has done like syntax idea is, bash makers has technical answer (last 10 years). There are many forums, where has been asked this question manymanmany times from other shell makers, why not.

Make function like command then no problem in any shell.

Here is solution for read problem in other than ksh (this solution works with ksh also):

gettime() {
read hour <<EOF
$(date '+%H')
EOF
TIME=${hour}
}

gettime
echo $TIME

This is better way to do function - works like command. My opinion.

gettime() 
{
   $(date '+%H')
}

TIME=$( gettime )
echo $TIME