[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 110: Undefined array key "cached"
[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 111: Undefined array key "normal"
[phpBB Debug] PHP Notice: in file /includes/db/dbal.php on line 112: Undefined array key "total"
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 885: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3391: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3393: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3394: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3395: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2922)
Cabrillo College Linux Classes • View topic - my project

my project

Introduction to UNIX/Linux

my project

Postby alexa bolas on Mon Dec 08, 2008 9:59 pm

I am trying to have 3 choices instead of 2.
Right now, I have the following, which is not working:

2) # To get the Calendar
echo "Hello, do you the day of the month or the julian date?"
echo -n "Enter 1 for date or 2 for julian date or 3 for 3 month output: "
read ANSWER
if [ "$ANSWER" = 1 ]; then
cal
then [ "$ANSWER" = 2 ]; then
cal -j
else
cal -3
fi
;;

When I type myscript, I get
line 33: syntax error near unexpected token `then'
line 33: ` then [ "$ANSWER" = 2 ]; then'
alexa bolas
 
Posts: 30
Joined: Wed Sep 03, 2008 7:28 pm

Re: my project

Postby Rich Simms on Mon Dec 08, 2008 11:41 pm

You need to change the second then to an elif (else if):
[code]
if [ "$ANSWER" = 1 ]; then
cal
elif [ "$ANSWER" = 2 ]; then
cal -j
else
cal -3
fi
;;
[/code]
(see page 583 in the textbook for more about the elif)

- Rich
User avatar
Rich Simms
Site Admin
 
Posts: 640
Joined: Thu May 15, 2008 2:44 pm

Re: my project

Postby alexa bolas on Tue Dec 09, 2008 9:46 am

Oh.. so now it makes a little more sense. thanks
alexa bolas
 
Posts: 30
Joined: Wed Sep 03, 2008 7:28 pm

Re: my project

Postby Michael Wicherski on Wed Dec 10, 2008 8:50 am

uhm don't you need a double == in the if statements as well since they are conditionals?

or does that not apply for shell scripts?

(although i think mine worked with double;; just checked, definitely worked with double)
Michael Wicherski
 
Posts: 140
Joined: Mon Sep 01, 2008 5:23 am

Re: my project

Postby Rich Simms on Wed Dec 10, 2008 10:21 am

Both ways will work, == is a synonym for =

See: [url]http://tldp.org/LDP/abs/html/comparison-ops.html[/url]

- Rich
User avatar
Rich Simms
Site Admin
 
Posts: 640
Joined: Thu May 15, 2008 2:44 pm

Re: my project

Postby Michael Wicherski on Wed Dec 10, 2008 9:49 pm

i'll stick to double or i will start having issues with java and other programming xD
Michael Wicherski
 
Posts: 140
Joined: Mon Sep 01, 2008 5:23 am


Return to CIS 90 - Fall 2008

Who is online

Users browsing this forum: No registered users and 0 guests

cron