![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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" |
|
|||
|
I found this in the Wikipedia article on the shell: Quote:
http://www.grymoire.com/Unix/CshTop10.txt Escape exclamation marks!!! Code:
echo "Congratulations\!\! You have guessed correctly\!" |
|
|||
|
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 |
|
|||
|
Quote:
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |