When I am using commnad:hostname in unix command prompt , it's printing the system name of my system but when I use this command in shell script it gives nothing.
Note the backticks around the "hostname" ---- `hostname` this executes command in a sub-shell and returns the value to the parent one. The other way is, as you have been told, to use the HOSTNAME variable, which is set on every session, verify with : "env | grep -i hostname" - you will receieve : HOSTNAME=your.host.name
In script, just call the variable, as in : echo $HOSTNAME.