[Solved] ksh script - can't figure out what's wrong


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] ksh script - can't figure out what's wrong
# 1  
Old 11-22-2012
[Solved] ksh script - can't figure out what's wrong

Hi!
(I guess this could of gone into the scripting forum, but Unix for Dummies seemed more appropriate. Please note that I am not in school, so Homework doesn't seem appropriate either. You guys can let me know if you think otherwise.)

I am following an exercise in a book on ksh scripting which is supposed to be about boolean operators. While I've added my own lame lines to print, and made changes mentioned below, I've otherwise copied from the book. This is the error I receive:
Code:
./boolean.ksh: line 6: syntax error at line 20: `"' unmatched

Now, I'm a total noob, and I'm probably missing something obvious, but no matter how hard I stare at lines 6 and 20, I cannot see anything wrong, especially not with the quotes. I mean, line 6 couldn't be simpler:
Code:
read age

The syntax in the book for the variables was as follows:
Code:
((age < 6))

I thought maybe that was it, because in previous examples they'd shown the syntax more like this:
Code:
(( (age < 6) ))

And they had emphasized how important white space was in ksh scripting, (although they never said exactly how). But changing it didn't make any difference. Even if it's not related to the error, I wouldn't mind hearing a comment about that.
But the fact is, I ran it in debug mode, and it never gets past my inputting the data, so the problem does seem to be line 6.

Here is the script:
Code:
#!/bin/ksh

# Please forgive my juvenile sense of humor.

print -n "Enter your age -- "
read age

if (( (age < 6) )) || (( (age > 64) ))		# || = boolean 'or'
then
	print "We give a discount to children and seniors."
	print "The price is \$100.00”
elif (( (age >= 13) && (age <= 19) ))			# && = boolean 'and'
then
	print "You are a teenager. We hate teenagers. Get lost."
elif (( (age >= 40 && age <= 45) ))
then
	print "Since you likely in a mid-life crisis, why not spend more? You will feel better about yourself.”
	print "Tickets are \$300.00.”
else
	print "Tickets are \$5.00"
fi


Last edited by sudon't; 11-22-2012 at 07:19 PM.. Reason: forgot something
# 2  
Old 11-22-2012
One of these is not like the others.

One of these just doesn't belong.



Do not type up your scripts in Microsoft Word, it will convert your ordinary quotes into "smart quotes" which aren't quotes at all as far as the shell's concerned.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-22-2012
Quote:
Originally Posted by Corona688
One of these is not like the others.

One of these just doesn't belong.



Do not type up your scripts in Microsoft Word, it will convert your ordinary quotes into "smart quotes" which aren't quotes at all as far as the shell's concerned.
Actually, I was using vim, but after I got the error the first time, I opened it in TextWrangler, and added the missing quotes. I see now that I had the prefs set to use "typographers quotes". But I guess my eyesight wasn't good enough to notice.
Ok, I changed prefs and replaced the curly quotes, and it works as expected. That was it, thanks!

Moderator's Comments:
Mod Comment edit by bakunin: Great! Changed the threads title to [Solved].

Last edited by bakunin; 11-25-2012 at 11:55 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Help with change significant figure to normal figure command

Hi, Below is my input file: Long list of significant figure 1.757E-4 7.51E-3 5.634E-5 . . . Desired output file: 0.0001757 0.00751 0.00005634 . . . (10 Replies)
Discussion started by: perl_beginner
10 Replies

3. Shell Programming and Scripting

Number comparison in ksh on mac with -lt is giving wrong answer

I am trying to run following script in ksh on darwin 11.4.2: freeSpace=2469606195 spaceNeeded=200 ] && echo "no space" || echo "space available" ] && echo "no space" || echo "space available" "-lt" is giving wrong answer as "no space" Whereas '<' works fine. When I change the freespace... (4 Replies)
Discussion started by: sabitha
4 Replies

4. Shell Programming and Scripting

[Solved] AIX ksh script -d <- what does it mean?

I'm looking at a line in a script: && DRROOT="/dir1" || DRROOT="/dir2" I'm trying to understand it. Is there a "-d" command and is it seeing if /dir1 exists and, if so, set an environment variable named DRROOT to "/dir1", else set DRROOT to "/dir2" ? Thanks, -dog ---------- Post... (0 Replies)
Discussion started by: landog
0 Replies

5. Shell Programming and Scripting

Anybody here can help me to figure thie perl script out?

Gey guys, I'm a new learner of perl. Now I encountered a problem when I tried to get the output below from the input file. Input: 5'h1f, 16'h8210 write, 5'h10, 16'h0000 write, 5'h11, 16'h0000 5'h1f, 16'hffd0 write, 5'h1e, 16'h0000 5'h1f, 16'h8310 read, 5'h10, rd_data 5'h1f,... (3 Replies)
Discussion started by: sunbaby
3 Replies

6. Shell Programming and Scripting

syntax of if condition in ksh is wrong

The syntax of 'if' conditionals in bash and ksh seems different. I am trying to check for a particular version using 'if' in ksh. This very simple syntax gives syntax error. I have tried many variants, but no go. Please correct the syntax. Later I will expand it to 'if' and 'else'. #!/bin/ksh... (8 Replies)
Discussion started by: nivedhitha
8 Replies

7. Shell Programming and Scripting

Bash script - im missing something and cant's figure out what

I just put together a script for work that will essentially automate the migration of our Windows fileserver to my newly created Debian based SAMBA server. My script will create the necessary directories then copy the data over to my new server, after that it will set the ACL's by using... (3 Replies)
Discussion started by: binary-ninja
3 Replies

8. Shell Programming and Scripting

Spent all day trying to figure this script out...

Before I begin with the question, I just want to point out that I just started learning unix in the middle of last week, so my code (and knowledge of how unix operates) is weak sauce. I took my best stab at this question but it's just not working. Assignment: Create a script named... (1 Reply)
Discussion started by: ashkali1
1 Replies

9. Shell Programming and Scripting

Function returns wrong values - solved

Hi I have a small function which returns a wrong value. The function tries to make a connection to oracle database and tries to get the open_mode of the database in the variable status. However when a database is down the value of the status column is set to READWRITE i am not sure why. I... (0 Replies)
Discussion started by: xiamin
0 Replies

10. Shell Programming and Scripting

What was wrong ??? ksh

I wrote this code and did not know what did I do wrong ?? ## get the first line of this file AFIRST=$(head -1 rss-cs-3423a-20051211-060001.dat) #CJKA|2005-12-10 08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111 <--- this is a answer ## Third line of stat file BTHREE=$(cat... (11 Replies)
Discussion started by: sabercats
11 Replies
Login or Register to Ask a Question