Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sorry for the length of this, but I have a homewaork question I thought I had answered until I tried it and got an error message I cant solve. Any help would be greatly apprecisted (I will post question and my attempt to answer it).
Question: Write a shell script that prompts the user for a grade between 0 and 100. The shell script should calculate the corresponding letter for this grade based on the following criteria:
0–49 ¼ F
50–59 ¼ D
60–69 ¼ C
70–79 ¼ B
80–100 ¼ A
Ensure that the shell script continues to prompt the user for grades until the user chooses to exit the shell script.
Did you read the error message?
What do you think the key "do" does?
Where is that key appropriate?
Did you read the BASH man page?
Have you examined the information about posting code here? There are markup tags that would help.
Many here will be willing to HELP you, but there is a policy about not doing anyone else's homework. Answers will have to be carefully crafted to lead you to find the answer yourself. That is not to frustrate you, that is part of our professional ethics standard and is GOOD for you. (Yeah, I hated hearing that phrase also, but it IS.)
Please review the LQ Rules and take note of the specific one saying:
Quote:
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
Also suggest you check the Site FAQ for information about how to use [code][/code] tags, or use the advanced edit mode and use the menu option.
Please follow the advice of hydrurga and wpeckham and note that LQ members are not here to do your work for you. You have attempted to do this, please continue.
A further suggestion is to put the line "set -xv" as the second line of your script.
A question I do have is "What should the first line of your script be?" What is shown is incorrect. Please look at some sample scripts to first answer that question.
Hi,
Sorry for the length of this, but I have a homewaork question I thought I had answered until I tried it and got an error message I cant solve. Any help would be greatly apprecisted (I will post question and my attempt to answer it).
Question: Write a shell script that prompts the user for a grade between 0 and 100. The shell script should calculate the corresponding letter for this grade based on the following criteria:
0–49 ¼ F
50–59 ¼ D
60–69 ¼ C
70–79 ¼ B
80–100 ¼ A
Ensure that the shell script continues to prompt the user for grades until the user chooses to exit the shell script.
My Code:
Code:
echo "Please enter your grade"
read GRADE
do
case $GRADE
"0-49")
echo "F"
;;
"50-59")
echo "D"
;;
"60-69")
echo "C"
;;
"70-79")
echo "B"
;;
"80-100")
echo "A"
;;
"q")
break
;;
*)
echo "invalid Option"
;;
esac
done
While you did post a verbatim homework question you actually DID show your own effort in doing this yourself...well done. Please, do not be discouraged, and continue to try to solve your own problems.
The beginners guide will walk you through some things you need to know, and get you up to speed quickly. You're missing the "while" in the while->do->done looping function: http://tldp.org/LDP/Bash-Beginners-G...ect_09_02.html
Try something like what can be found here, as there's a script on that page that covers such things, that you SHOULD be able to modify (given your efforts), and make work in short order. http://tldp.org/LDP/Bash-Beginners-G...ect_09_05.html
...and for integer testing, try using
Code:
(("$a" <= "$b"))
..for a "less than or equal to". Replace with > for (obviously) GREATER than or equal to.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.