LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-14-2014, 07:11 PM   #1
linuxnewbie1995
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 05-14-2014, 07:35 PM   #2
linuxnewbie1995
LQ Newbie
 
Registered: May 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Any help would be greatly appreciated. I could really use it.
 
Old 05-14-2014, 07:37 PM   #3
DJ Shaji
Member
 
Registered: Dec 2004
Distribution: Fedora 22 (Twenty Two!), ArchLinux
Posts: 506
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
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.
 
Old 05-14-2014, 07:40 PM   #4
linuxnewbie1995
LQ Newbie
 
Registered: May 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
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.
 
Old 05-14-2014, 07:56 PM   #5
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
You'll probably need to use the 'date' command, so I would look at the man page or look it up online.
 
Old 05-14-2014, 08:26 PM   #6
linuxnewbie1995
LQ Newbie
 
Registered: May 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Anyone with more help please??
 
Old 05-14-2014, 08:35 PM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
Old 05-14-2014, 08:48 PM   #8
DJ Shaji
Member
 
Registered: Dec 2004
Distribution: Fedora 22 (Twenty Two!), ArchLinux
Posts: 506
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
Bash is real simple buddy. There will come a day when your code will segfault, and you'll be tearing your hair out
 
Old 05-14-2014, 09:37 PM   #9
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
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
 
Old 05-14-2014, 10:27 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by metaschima View Post
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.
 
Old 05-15-2014, 06:06 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 05-15-2014, 07:47 AM   #12
DJ Shaji
Member
 
Registered: Dec 2004
Distribution: Fedora 22 (Twenty Two!), ArchLinux
Posts: 506
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
He needs to output the date. How would date help in calculations ?
 
Old 05-15-2014, 09:44 AM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,921

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by linuxnewbie1995 View Post
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.
 
Old 05-15-2014, 11:35 AM   #14
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
Quote:
Originally Posted by evo2 View Post
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.
 
Old 05-15-2014, 08:27 PM   #15
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,
Quote:
Originally Posted by DJ Shaji View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help making this very simple bash script. mxmaniac Linux - Newbie 6 02-28-2014 03:26 AM
Making a simple Linux based OS ashish Programming 5 12-07-2009 03:03 AM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 06:34 PM
Help making a simple script for mencoder. joney_bravo Programming 3 01-01-2007 07:28 PM
Making a simple file server - which OS? DaveSalt Linux - Software 2 02-26-2005 08:19 AM


All times are GMT -5. The time now is 11:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration