shell script
hello, 'I had to make a script in bash, cant i cant get it to work, as you can probably tell is pretty much just works off the system time and outputs a different greeting depending on the time...
if date+%H < 12 >= 24; then echo Good Morning else if date+%H <=12 >5 echo Good Afternoon else if date+%H <=8 >24 echo Good Night fi What am i doing wrong?? Thanks for your help! Greg |
did you remember to include the /bin/bash header in the top?
|
I think my problem has something to do with the else if statement, because if i just have
Code:
echo "The hour is " date+%H i dont think my syntax is correct... |
This kinda sounds like homework so here are some hints...
now=`date +%H` use -le , -gt , and -a use if , elif , else and fi use echo " Something" |
you must have that ` in the beginning and the end of the command. So the command should be:
echo "the hour is" `date +%H`. no neeed to have that space inside the quotation for "the hour is". How about: #!/bin/bash a=`date +%H` if [ "$a" -lt 12 ] && [ "$a" -ge 24 ] then echo "Good Morning" elif [ "$a" -le 12 ] && [ "$a" -gt 5 ] then echo "Good Afternoon" else echo "Good Night" fi you can replace that [ "$a" -lt 12 ] syntax with (("$a" < 12)). take note the space in [] before the variable as compared to variable inside the (()). |
Code:
if [ $wang -le 12 -a $wang -gt 24 ] then anyone have any ideas??? |
Code:
wang=`date +%H` thanks guys |
where are those quotation marks? that " " to include variable? you'll need that. ;)
|
only if you want to break it
|
Quote:
if [ "$wang" -le 12 ] then echo "bla bla bla" fi ? It is the correct syntax in Advanced Bash Scripting Guide by Mendel Cooper. Please correct me if i'm wrong with this. |
All times are GMT -5. The time now is 05:02 PM. |