Question:
Write a shell script.?
TEQUILA O
2010-11-28 17:58:26 UTC
Write a shell script to read from the keyboard and display on the monitor first name, last name and age for 5 people. Use 3 different variable names and a "While Loop" for reading and displaying this information.
Three answers:
Unca Alby
2010-11-28 18:06:03 UTC
Another homework assignment, hmmm?



Why don't you give it a try first and see how far you can get on your own, then come back later if you have troubles with a SPECIFIC QUESTION.



After all, this is Yahoo! Answers, not Yahoo! Do My Homework For Me.
Sarah U
2010-11-30 20:40:54 UTC
I agree with uncle.



You didn't even show that you made an attempt at this.

What kind of format are you supposed to input the information in?

For example, do you want the script to ask the user for the information? (*script says* please input the lastname. *user types lastname*)



You just copied your homework instructions and expect us to magically find a solution for you.



Well, I'll give you a little lesson on the while loop, and you can figure it out yourself from there.



the while loop is something you do to keep executing a bunch of commands over and over again if a certain "condition" is true.

The conditions can be numerical comparisons, like if $variable1 is greater than $variable2

(( $variable1 > $variable2 ))

or if a certain variable equals a certain string

[[ $variable1 == "poop" ]]

that kind of stuff.

or just the exit status of a command, such as

grep cow animalfile (if a line with the word "cow" is found in the file, it will register as 0 (True) if it is not, it will register as 1 (false). The while loop only does its stuff it the status was true.



Something you could do with a while loop is



echo "please enter your name"

read myname



while [[ "$myname" == "Jack" ]]

do

echo "Hi, my cousins name is Jack"

echo "please enter your name again"

read myname

done



The script will ask the user to enter his name. If his name is "Jack", then it will do whatever is between the words "do" and "done" over and over again, as long as his name is still Jack; in this case, it will say "Hi, my cousins name is Jack" and ask the user for his name again. If his he enters Jack, it will keep doing it over and over, but if he enters something else, it will stop asking him.



Just so you know, if it didn't ask for his name again in the while loop, it would keep on telling him forever that his cousins name was Jack. Stopping the loop is called loop control.



You want to ask the names and ages for 5 people, so you have to do whatever is in the while loop 5 times (make some variable equal to 0 and use something called a variable increment in your while loop, which adds the number 1 to a variable every time the loop executes) and in the while loop conditional statement, say that you want to do it as long as that variable is less than 5.



You'll have to use 3 variables that will accept multiple values in one variable, called an array. You should read it yourself and figure out how to do it.
2016-10-18 13:12:08 UTC
i'm guessing that's homework? :P somebody will in all probability provide you the respond yet what i will say is basically take a seat and calculate it out with the occasion you gave. Do it on a sheet of paper, then use that sheet of paper to create your code.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...