|
|
unix coursework help!!!!
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status:
Offline
|
|
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.
)
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status:
Offline
|
|
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).
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2001
Location: On the move again...
Status:
Offline
|
|
The AT&T korn shell is available under FINK, in the unstable tree, if you wanted to install it in OS X.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Oct 2001
Location: Philly
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: May 2002
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jul 2003
Location: England
Status:
Offline
|
|
I finally have completed it!!
Thanks all for your help!
Think i have learnt more here than in my tutorials!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|