LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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

Reply
 
Search this Thread
Old 03-07-2013, 07:36 AM   #1
Anon46
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Rep: Reputation: Disabled
Need help with shell script (easy one)!


Hello, all! I'm new around these parts, and just needed some quick help with a shell script.

I'm taking my first intro to linux course and just needed help scripting a simple program.

I need to write a script which accepts any of these three words: "Color, Drink, Animal", and sorts the output accordingly.

So, basically, when I run the program I need it to list like this [1) Color, 2) Drink, 3) Animal], and ask what input. Depending on the input, I need it to locate a file (in this case depending on the input, I want it to read the files color.sh, drink.sh, or animal.sh), and then display what I have written in them.

Thanks for the help to anyone that reads this.
 
Old 03-07-2013, 07:55 AM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,473
Blog Entries: 6

Rep: Reputation: Disabled
smells like homework?
 
Old 03-07-2013, 08:09 AM   #3
Anon46
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
smells like homework?
Actually, it's not graded homework.

It was just an assignment from a list of scripts to practice, and this was the final one. I've spent hours on it and I wanted to get some help since through research and my book I haven't been able to get anything to work.
 
Old 03-07-2013, 08:21 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Try:
Code:
#!/bin/bash
echo -n "Enter your choice [1. Color, 2. Drink, 3. Animal]: "; read ans
case $ans in
1) cat color.sh ;;
2) cat drink.sh;;
3) cat animal.sh;;
*) echo "Wrong choice entered, exiting!";;
esac

Last edited by shivaa; 03-07-2013 at 08:23 AM. Reason: Typo
 
Old 03-07-2013, 08:22 AM   #5
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,473
Blog Entries: 6

Rep: Reputation: Disabled
shivaa is on Fire today!
 
Old 03-07-2013, 08:26 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
Originally Posted by Habitual View Post
shivaa is on Fire today!
Lolzz... Things may be complicated for people, but if you keep enjoying them, you will be on fire!
 
Old 03-07-2013, 05:34 PM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
@Anon46: here are some good links for future ref
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 03-07-2013, 05:38 PM   #8
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,473
Blog Entries: 6

Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Lolzz... Things may be complicated for people, but if you keep enjoying them, you will be on fire!
everywhere I "went" here at LQ this morning, you had already posted, hence "on Fire".
 
  


Reply


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
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
[SOLVED] script help (Case & IF statement syntax), easy to answer if you know shell scripting. casperpache Linux - Newbie 12 05-09-2011 07:18 AM
Easy Shell Script Question scriptn00b Linux - Newbie 8 09-04-2005 07:09 AM
easy shell script question RDove Programming 4 02-15-2005 06:26 PM


All times are GMT -5. The time now is 01:58 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