Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > unix coursework help!!!!

unix coursework help!!!!
Thread Tools
student
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status: Offline
Reply With Quote
Jul 22, 2003, 06:58 AM
 
Hello everyone i hope you can help!!

i'm currently doing a unix course (using the korn shell).

i have been set a task to create a program in unix that allows a user to:

-enter his/her name
-the group he/she is in (either A B or C)
-who is his/her tutor (one of Mr A, Mrs B or Miss C)
-what date and time he entered the information

the information is to be recorded in a file.

if anyone can help me at all i would be very grateful.

Thank you in advance,

Levi
( Last edited by student; Jul 22, 2003 at 12:34 PM. )
     
Ludovic Hirlimann
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status: Offline
Reply With Quote
Jul 22, 2003, 09:19 AM
 
Originally posted by student:
Hello everyone i hope you can help!!

i'm currently doing a unix course (using the korn shell).

i have been set a task to create a program in unix that allows a user to:

-enter his/her name
-the group he/she is in (either A B or C)
-who is his/her tutor (one of Mr A, Mrs B or Miss C)
-what date and time he entered the information

the information is to be recorded in a file.

if anyone can help me at all i would be very grateful.

Thank you in advance,

Levi
If we do it for you, you 'll never learn how to use/debug such things. Korn shell is not presnt on OS X, but bash can be a replacement, if you do not like bash I suggest you try pdksh which is quite good (but I don't know if it's been ported to OS X).
     
drmbb2
Forum Regular
Join Date: Jun 2001
Location: On the move again...
Status: Offline
Reply With Quote
Jul 22, 2003, 09:52 AM
 
The AT&T korn shell is available under FINK, in the unstable tree, if you wanted to install it in OS X.
     
student  (op)
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status: Offline
Reply With Quote
Jul 22, 2003, 10:21 AM
 


i don't want you to do it all for me i just need to get started.

i have so far made a directory using mkdir and called it 'info' for all records to be stored in. the editor i use is vi which i can read the info with but i'm not sure how to store the information in the file. do i have to use 'readln'?

I have to put this at the beginning for it to work:

#!/bin/ksh

Does the ksh determine the shell (i.e. the korn shell)?

Thanks!

I just need a poke in the right direction
     
Ludovic Hirlimann
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status: Offline
Reply With Quote
Jul 22, 2003, 10:43 AM
 
Originally posted by student:
information in the file. do i have to use 'readln'?

I have to put this at the beginning for it to work:

#!/bin/ksh

Does the ksh determine the shell (i.e. the korn shell)?

Thanks!

I just need a poke in the right direction
Ok, yes the ksh says it's should be interpreted the korn shell way.
Readln is not the way try read and echo which should help, you.
Best way to leran shell script is to find some sample read it and read the manual of the shell at the same time. You can also buy some books on shell programming. If you need an advice says so.
     
student  (op)
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status: Offline
Reply With Quote
Jul 22, 2003, 11:08 AM
 
thanks, so far i have this:

-----------------------------------------------------------
#!/bin/ksh

echo "please enter your name:"
read name

echo "please enter your group:"
read group

echo "please enter your tutor:"
read tutor
---------------------------------------------------------

i'm not sure on how to record the date next to the information is their a specific command? i can't find one in the man pages.

also could i use an if statement to validate the information being put in? would this work:

echo "please enter your group"
read group

if $group = 'A' or 'B' or 'C' then
echo "group accepted"
else
echo "group invalid, please re-enter group"
read group
fi

thanks again
     
student  (op)
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status: Offline
Reply With Quote
Jul 22, 2003, 03:40 PM
 
hey i got this far:


------------------------------------------------------------
#!/bin/ksh

echo �Please enter your first name � �
read first

echo �Please enter your surname � �
read surname

echo �Hello $first $surname, please enter your group � �
read group

case $group in
A | B | C)
Echo �Group accepted�
;;

*)
echo �Error in group data�
exit
;;
esac

echo �Please enter your Tutor�s name � (initial and surname)�
read tutor

case $tutor in
J.Rosbottom | V.Wong | S.Walters)
Echo �Tutor confirmed as $tutor�
;;

*)
echo �Invalid tutor name�
exit
;;
esac

echo �What project activities have you undertaken in the last week? � �
read activities

echo �Please enter date of meeting � �
read meeting
echo �Please enter time of meeting - �
read time
echo �Please enter place of meeting - �
read place

echo �Confirmation of meeting on date $meeting at time $time and place $place Y/N �
read ans


if [$ans = �N�] then
echo �Meeting information incorrect, please re-start�
exit
else
echo �Meeting information confirmed�
fi
-----------------------------------------------------------

will this work?? (i don't have an emulator yet).
anything that needs changing please let me know,

thanks.
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 22, 2003, 03:54 PM
 
If you have OSX, kork shell is a bourne-compatible shell. You can run on OSX no problem. Here is your code, with a few fixes:

Code:
#!/bin/sh echo "Please enter your first name: " read first echo "Please enter your surname: " read surname good_group=0 while [ $good_group == 0 ]; do echo "Hello $first $surname, please enter your group: " read group case $group in A | B | C) echo "Group accepted" good_group=1 ;; *) echo "Error in group data" #exit ;; esac done echo "Please enter your Tutor's name: (initial and surname)" read tutor case $tutor in J.Rosbottom | V.Wong | S.Walters) echo "Tutor confirmed as $tutor" ;; *) echo "Invalid tutor name" exit ;; esac echo "What project activities have you undertaken in the last week? " read activities echo "Please enter date of meeting: " read meeting echo "Please enter time of meeting: " read time echo "Please enter place of meeting: " read place echo "Confirmation of meeting on date $meeting at time $time and place $place Y/N " read ans if [ $ans == "N" ]; then echo "Meeting information incorrect, please re-start" exit else echo "Meeting information confirmed" fi
( Last edited by Arkham_c; Jul 22, 2003 at 04:08 PM. )
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
rantweasel
Dedicated MacNNer
Join Date: Oct 2001
Location: Philly
Status: Offline
Reply With Quote
Jul 22, 2003, 03:56 PM
 
Originally posted by student:
i'm not sure on how to record the date next to the information is their a specific command? i can't find one in the man pages.
man date


also could i use an if statement to validate the information being put in?
Yes indeedy, and it's a good idea. You may want to put it in a loop instead of just asking again (in other words, while group != 'A' or 'B' or 'C', keep prompting reading group), that way the user can make plenty of typos if they need to.

mathias
     
student  (op)
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status: Offline
Reply With Quote
Jul 22, 2003, 04:48 PM
 
thanks for all your help!!

all i need to do now is to append the information to a file, do i use >> to do this?

i.e. echo $surname >> information.txt

if i do this for each vairiable i.e first, surname, time, date etc

will it give me a file with all the information in it?

thank you
     
theory
Dedicated MacNNer
Join Date: May 2002
Status: Offline
Reply With Quote
Jul 22, 2003, 07:57 PM
 
Did you try it using the sh instead of ksh?
It should work. Just two sugestions

-Put a seperator between records so you
know when they start and when they finish.

-Put a loop around the part where you
are reading the meeting.

Yeah and echo $something >> file should work
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 22, 2003, 10:27 PM
 
If you have a lot of data, and you want it organized nicely, cat will work better than echo:

Code:
cat << EOF >> information.txt First Name: ${first} Last Name: ${surname} Group: ${group} Tutor: ${tutor} ----- EOF
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
student  (op)
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status: Offline
Reply With Quote
Jul 23, 2003, 03:59 AM
 
I finally have completed it!!

Thanks all for your help!

Think i have learnt more here than in my tutorials!

     
   
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 02:23 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,