LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Closed Thread
 
Search this Thread
Old 04-30-2005, 02:04 AM   #1
lostinsyntax
LQ Newbie
 
Registered: Apr 2005
Posts: 5

Rep: Reputation: 0
Question Difficulties writing shell scripts


I dont like to take up people's time but I have taken the below shell scripts as far as I can. I dont think I am capable of any more, and I guess I hate to say it but I need help. Thanks in advance for any assistance anyone can provide. Sorry to be burdonsome. PS: These have been written in vi text editor.

Question
Write a shell script that will greet you with “Good Morning” if the time is between 12.00am to 11.59am, “Good Afternoon” if the time is between 12.00pm to 4.59pm, “Good Evening” if the time is between 5.00pm to 7.59pm and “Good Night” if it is between 8.00pm to 11.59pm.

Answer
greet=`date | cut –c12-13,15-16`;
if [ “$greet” => “0000” –a “$greet” <= “1159” ];
then
echo “Good Morning!”;
else
if [ “$greet” => “1200” –a “$greet” <= “1659” ];
then
echo “Good Afternoon!”;
else
if [ “$greet” => “1700” –a “$greet” <= “1959” ];
then
echo “Good Evening”;
else
echo “Good Night”
fi
fi
fi

Question
Write a shell script which will display a menu as follows and accepts an input key from the user to execute an option on the menu.

My Menu
~~~~~~~
1) Display today’s date and system uptime
2) Display calendar for a particular month and year
3) Display current logon users
4) Find a file
5) Exit from menu
Please enter your choice (1-5):

For option 2 the user must be allowed to enter the month and the year for calendar display. For option 4 you must use the find command to find the file and the user must be allowed to enter the filename and the name of the directory for the search. Your shell script should run continuously until the user enters 5 for exit.


Answer
tput clear;
tput cup 3 17; echo “My Menu”;
tput cup 4 17; echo “~~~~~~~”;
tput cup 6 12; echo “1) Display today’s date and system uptime”;
tput cup 7 12; echo “2) Display calendar for a particular month and year”;
tput cup 8 12; echo “3) Display current logon users”;
tput cup 9 12; echo “4) Find a file”;
tput cup 10 12; echo “5) Exit from menu”;
tput cup 11 17; echo “Please enter your choice (1-5):”; tput cup 11 49;
read choice
if [ “$choice” = “1” ];
then
tput cup 12 17; date
else
if [ “$choice” = “2” ];
then
tput cup 12 17; echo “Please enter month:”; tput cup 12 37;
read month
tput cup 13 17; echo “Please enter year:”; tput cup 13 37;
read year
cal
else
if [ “$choice” = “3” ];
then
tput cup 12 17; who
else
if [ “$choice” = “4” ];
then
tput cup 12 17; echo “What is the name of the directory?”; tput cup 12 52;
read directory
tput cup 13 17; echo “What is the filename?”; tput cup 13 52;
read filename
tput cup 14 17; find /directory –name filename
else
exit
fi
fi
fi
fi
 
Old 04-30-2005, 03:22 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php
 
Old 05-01-2005, 04:48 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Closed per the above ...
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulties writing shell scripts lostinsyntax Programming 8 05-02-2005 08:42 AM
I'm terrible at writing shell scripts. A little help fetching files? ashibaka Linux - General 6 04-10-2004 01:41 AM
Writing Shell Scripts in Redhat 6.1 KDE Ace Rimmer Linux - Newbie 3 03-30-2004 03:31 PM
Writing C++ Shell Scripts MasterKin8T Programming 5 09-29-2003 11:43 AM
writing Linux shell scripts in Windows NightWolf_NZ Linux - Newbie 3 09-10-2003 10:28 PM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration