The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Homework & Coursework Questions
.
grep unix.com with google



Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-19-2009
Registered User
 

Join Date: Nov 2009
Posts: 3
Beginner Scripting Issue

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
The object is to enter a number, then have another classmate guess the entered number.


2. Relevant commands, code, scripts, algorithms:
I am trying to use an if-then-else statement to accomplish my goal


3. The attempts at a solution (include all code and scripts):
#! /bin/csh
echo "Please select a number to be guessed"
read num1
1:
echo "Please guess a number"
read num2
if (num2 == num1) then


echo "Congratulations!! You have guessed correctly!"
else
echo "Sorry, but that number is incorrect."
goto 1
endif



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):


Washtenaw Community College, Ann Arbor MI, USA, Doug Cox, CIS 121

<Hoping I did the template correctly>

The problem I am encountering is that no matter what number I enter, it always echos "Sorry, but that number is incorrect" even if I enter, say 11, for both num1 and num2. And yes, I am a complete coding noob. xD
  #2 (permalink)  
Old 11-19-2009
scottn scottn is offline Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,611
In my cshell there is no read build-in.

As I remember, the way to read is:


Code:
set num1 = $<

In any case when you access the values of num1 and num2, they are variables, and should be referenced as $num1 and $num2

i.e.

Code:
if ( $num2 == $num1 )

I'm struggling to understand why anyone would teach c-shell... it really is dreadful.
  #3 (permalink)  
Old 11-19-2009
Registered User
 

Join Date: Nov 2009
Posts: 3
Thanks for the reply scottn,

I think I understand what you said so I changed my coding to the following:

#! /bin/csh
echo "Please select a number to be guessed"
set num1 = $<
1:
echo "Please guess a number"
set num2 = $<
if ( $num2 == $num1 ) then


echo "Congratulations!! You have guessed correctly!"
else
echo "Sorry, but that number is incorrect."
goto 1
endif


---After executing it lets me enter the first two numbers and then it returns the error "Event not found"
  #4 (permalink)  
Old 11-19-2009
scottn scottn is offline Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,611
I found this in the Wikipedia article on the shell:

Quote:
Another known problem of csh is its message "0 event not found", which yields no information about what the problem is.
I'd read this:
http://www.grymoire.com/Unix/CshTop10.txt

Escape exclamation marks!!!


Code:
echo "Congratulations\!\! You have guessed correctly\!"

  #5 (permalink)  
Old 11-19-2009
Registered User
 

Join Date: Nov 2009
Posts: 3
Wonderful..heh

What shell would you recommend doing this in? I dont think there are any requirements as to what shell to use. Are there any that might be better suited for my needs?

P.s. I appreciate the help
  #6 (permalink)  
Old 11-19-2009
scottn scottn is offline Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,611
See what forum members think:

What's your most useful shell?


(and I should add, before someone reminds me, it's really bad practice to use goto's!)

Last edited by scottn; 11-19-2009 at 07:12 PM.. Reason: goto's
  #7 (permalink)  
Old 11-19-2009
Registered User
 

Join Date: Nov 2009
Posts: 37
Quote:
Originally Posted by scottn View Post
See what forum members think:

What's your most useful shell?


(and I should add, before someone reminds me, it's really bad practice to use goto's!)
haha i was about to say the exact same thing. it's been ages since i last saw a goto statement
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Scripting issue chief2000 Shell Programming and Scripting 8 09-22-2009 05:51 AM
scripting issue mraghunandanan Shell Programming and Scripting 1 05-19-2009 07:36 AM
Beginner bash scripting - a few problems traxy Shell Programming and Scripting 1 05-14-2009 04:52 AM
Scripting issue.. mraghunandanan Shell Programming and Scripting 4 04-30-2009 12:19 PM
Scripting issue.. mraghunandanan Shell Programming and Scripting 1 04-30-2009 10:59 AM



All times are GMT -4. The time now is 01:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0