LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help with shell script (easy one)! (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-shell-script-easy-one-4175453109/)

Anon46 03-07-2013 07:36 AM

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.

Habitual 03-07-2013 07:55 AM

smells like homework?

Anon46 03-07-2013 08:09 AM

Quote:

Originally Posted by Habitual (Post 4906678)
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.

shivaa 03-07-2013 08:21 AM

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


Habitual 03-07-2013 08:22 AM

shivaa is on Fire today! :)

shivaa 03-07-2013 08:26 AM

Quote:

Originally Posted by Habitual (Post 4906707)
shivaa is on Fire today! :)

Lolzz... Things may be complicated for people, but if you keep enjoying them, you will be on fire! :)

chrism01 03-07-2013 05:34 PM

@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/

Habitual 03-07-2013 05:38 PM

Quote:

Originally Posted by shivaa (Post 4906713)
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".


All times are GMT -5. The time now is 12:37 AM.