LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help making simple script (https://www.linuxquestions.org/questions/linux-newbie-8/help-making-simple-script-4175505026/)

linuxnewbie1995 05-14-2014 06:11 PM

Help making simple script
 
I would really appreciate some help with this script I am trying to make. If someone could help me, I would really appreciate it. Thank you.

The script needs to ask the users name and age and then output one of the below two statements depending on their age.

"Name" you are old enough to purchase alcohol.
"Name" you are not old enough to purchase alcohol.

After this the script needs to output today's date.
Then it should ask if the user would like to create a directory. If they enter a y for yes then it should ask for the absolute path of the directory and create it for them.

linuxnewbie1995 05-14-2014 06:35 PM

Any help would be greatly appreciated. I could really use it.

DJ Shaji 05-14-2014 06:37 PM

Mmm, is this homework? Coz it's really simple. You could easily do it yourself if you tried. I mean very easily. CLick here to begin.

linuxnewbie1995 05-14-2014 06:40 PM

This is one of MANY homework assignments I have that deal with bash scripts. If someone could just help me out with this one, you would be helping me more than you could imagine.

metaschima 05-14-2014 06:56 PM

You'll probably need to use the 'date' command, so I would look at the man page or look it up online.

linuxnewbie1995 05-14-2014 07:26 PM

Anyone with more help please??

evo2 05-14-2014 07:35 PM

Hi,

you won't need to use the date command. You'll need to use "read" to get input from the user, then an "if" statement to determine if what to output and then "echo" to write the output to the terminal. Telling you any more than that would essentially be doing your homework for you, and if we do that you won't really be learning, and you won't be able to do any of your more difficult homework.

So, do some reading (presumably you have course notes, and the link posted by DJ Shaji looks good) and then try to write the script. If you have problems, show us what you have done, explain the problem and we can make suggestions to help you.

Cheers,

Evo2.

DJ Shaji 05-14-2014 07:48 PM

Bash is real simple buddy. There will come a day when your code will segfault, and you'll be tearing your hair out :p

metaschima 05-14-2014 08:37 PM

Using the 'date' command can simplify the calculation, which can be complex.

Some examples, but not exactly what you want:
http://unix.stackexchange.com/questi...te-differences
http://stackoverflow.com/questions/5...date-variables
http://stackoverflow.com/questions/8...urs-bash-shell

evo2 05-14-2014 09:27 PM

Hi,
Quote:

Originally Posted by metaschima (Post 5171108)
Using the 'date' command can simplify the calculation, which can be complex.

What calculation? OP makes no mention of dates, just ages. Eg

Code:

if [ $age -ge $legal_dring_age ] ; then
Evo2.

chrism01 05-15-2014 05:06 AM

This is a good link http://rute.2038bug.com/index.html.gz.

As mentioned above though, read those links, then start writing your own code and come back if you get stuck.

DJ Shaji 05-15-2014 06:47 AM

He needs to output the date. How would date help in calculations ?

TB0ne 05-15-2014 08:44 AM

Quote:

Originally Posted by linuxnewbie1995 (Post 5171056)
This is one of MANY homework assignments I have that deal with bash scripts. If someone could just help me out with this one, you would be helping me more than you could imagine.

If you know you've got lots of homework that deals with bash scripting, wouldn't it be better if you learned how to write your own scripts?? We will always be glad to HELP you, but we aren't going to write your scripts FOR YOU, whether it's homework or not.

There are over one MILLION hits in Google for "bash scripting tutorial". The three best are:
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/abs/html/

All complete with examples and full explanations. Start there.

metaschima 05-15-2014 10:35 AM

Quote:

Originally Posted by evo2 (Post 5171131)
Hi,

What calculation? OP makes no mention of dates, just ages. Eg

Code:

if [ $age -ge $legal_dring_age ] ; then
Evo2.

Alright, well that is much much simpler. I assumed that the homework would be harder than this.

evo2 05-15-2014 07:27 PM

Hi,
Quote:

Originally Posted by DJ Shaji (Post 5171327)
He needs to output the date.

Opps, I missed that. Seems I didn't read the final paragraph. Indeed the "date" command is the obvious choice here.

Quote:

How would date help in calculations ?
Seems there aren't any calculations to be done.

Evo2.


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