LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-14-2004, 12:37 AM   #1
Greg_courageous
LQ Newbie
 
Registered: Apr 2004
Posts: 13

Rep: Reputation: 0
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
 
Old 05-14-2004, 01:08 AM   #2
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
did you remember to include the /bin/bash header in the top?
 
Old 05-14-2004, 01:22 AM   #3
Greg_courageous
LQ Newbie
 
Registered: Apr 2004
Posts: 13

Original Poster
Rep: Reputation: 0
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
it works

i dont think my syntax is correct...
 
Old 05-14-2004, 02:01 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
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"
 
Old 05-14-2004, 02:25 AM   #5
chii-chan
Member
 
Registered: Sep 2003
Location: chikyuu (E103N6)
Distribution: Redhat 8.0 (2.4.25-custom), Fedora Core 1 (2.4.30-custom)
Posts: 357

Rep: Reputation: 30
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 (()).

Last edited by chii-chan; 05-14-2004 at 02:27 AM.
 
Old 05-14-2004, 02:35 AM   #6
Greg_courageous
LQ Newbie
 
Registered: Apr 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Code:
if [ $wang -le 12 -a $wang -gt 24 ] then
       echo Good Morning
fi

if [ $wang -le 17 -a $wang -gt 12 ] then
       echo Good Afternoon
fi

if [ $wang -le 24 -a $wang -gt 17 ] then
       echo Good Night
fi

exit 0
still doesnt work
anyone have any ideas???
 
Old 05-14-2004, 02:41 AM   #7
Greg_courageous
LQ Newbie
 
Registered: Apr 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Code:
wang=`date +%H`


if [ $wang -le 12 -a $wang -gt 24 ]
then
       echo "Good Morning"
elif [ $wang -le 17 -a $wang -gt 12 ]
then
       echo "Good Afternoon"

else [ $wang -le 24 -a $wang -gt 17 ]

       echo "Good Night"
fi
works perfect =)
thanks guys
 
Old 05-14-2004, 02:42 AM   #8
chii-chan
Member
 
Registered: Sep 2003
Location: chikyuu (E103N6)
Distribution: Redhat 8.0 (2.4.25-custom), Fedora Core 1 (2.4.30-custom)
Posts: 357

Rep: Reputation: 30
where are those quotation marks? that " " to include variable? you'll need that.

Last edited by chii-chan; 05-14-2004 at 03:20 AM.
 
Old 05-14-2004, 03:50 AM   #9
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
only if you want to break it
 
Old 05-14-2004, 04:01 AM   #10
chii-chan
Member
 
Registered: Sep 2003
Location: chikyuu (E103N6)
Distribution: Redhat 8.0 (2.4.25-custom), Fedora Core 1 (2.4.30-custom)
Posts: 357

Rep: Reputation: 30
Quote:
Originally posted by SciYro
only if you want to break it
What do you mean? Is it going to break the script if it is like this:

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 07:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-12-2005 12:08 AM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 04:00 PM


All times are GMT -5. The time now is 10:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration