lundi 3 août 2015

Fedora assign date to a variable to get an integer

I'm new in linux environment and shell programming. Im trying to do a simple shell scripting program where I want to display "Good Morning" Good Afternoon" Good Evening" or "Good Night" according to the time in the system. I want to do this using date function as well. Below is the code I've typed to do the above task.

#!bin/bash 
$ say=$(date +%H)
echo "echoo  $say"
if [ "$say" -gt 18 ]
then
var="Night"
elif [ "$say" -gt 15 ]
then
var="Evening"
elif [ "$say" -gt 12 ]
then
var="Afternoon"
else
var="Morning"
fi
echo "hello $USER , $var"

What I planned to do here is get the hours part to a variable and check in which range that integer falls in to give the variable morning,night or whatever the value matches. Below is the output I get when I execute the shell script

time.sh: line 3: $: command not found
echoo  
time.sh: line 8: [: : integer expression expected
time.sh: line 12: [: : integer expression expected
time.sh: line 16: [: : integer expression expected
hello achala , Morning

Please help me through this. Thanx in advance.

Aucun commentaire:

Enregistrer un commentaire