Need help getting started simple simple shell script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Need help getting started simple simple shell script
OKAY I need help getting started with a simple and dumb shell script but we all have to start somewhere right?
Okay Here is what I have so far
#!/bin/sh
#by Drew Honnoll
#Just a dumb script to practice user imput and screen oupt
NEWAGE=
GRANDCHILDREN=
echo "Please enter your name and press enter"
read name
echo "Please enter the number of children you have and press enter"
read children
echo "Please enter your age when you had your last child and press enter"
read age
echo "Now, $name if your children have 2 children each by the time they are at least 25, then by the time you are $NEWAGE you will have $GRANDCHILDREN grandchildren"
What I don't know and what every attempt of mine has failed is getting NEWAGE and GRANDCHILDREN set up
NEWAGE needs to be a math equation of $age + 25
and GRANDCHILDREN needs to be an equation of $children * 2 How do I go about doing that?
Your first line (#!/bin/sh) should be telling the computer to execute the remainder of the script as if it were in the Bourne shell (sh). Most Linux distributions have a link from sh to bash (Bourne Again Shell). (This is why I had assumed that you were using bash.) If you want to run it in Korn, it should read
Code:
#!/bin/ksh
I don't do much in Korn (ok, nothing actually), but have tried the same commands, and it should work. The error that you are getting makes it look like you are trying to run something called "wrongcommand" from the command line.
Did you remember to change the permissions on your script so that it can be run? If your script is say age.sh, then you would want to add execute permissions to it.
Your first line (#!/bin/sh) should be telling the computer to execute the remainder of the script as if it were in the Bourne shell (sh). Most Linux distributions have a link from sh to bash (Bourne Again Shell). (This is why I had assumed that you were using bash.) If you want to run it in Korn, it should read
Code:
#!/bin/ksh
I don't do much in Korn (ok, nothing actually), but have tried the same commands, and it should work. The error that you are getting makes it look like you are trying to run something called "wrongcommand" from the command line.
Did you remember to change the permissions on your script so that it can be run? If your script is say age.sh, then you would want to add execute permissions to it.
Code:
chmod u+x age.sh
Then run the script.
Code:
./age.sh
You might not get what you expect on Ubuntu if you assume #!/bin/sh points to #!/bin/bash. #!/bin/sh points to /bin/dash, and you might find the need to use #!/bin/bash explicitly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.