LinuxQuestions.org
Review your favorite Linux distribution.
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 02-17-2017, 12:42 PM   #1
Ziggy2017
LQ Newbie
 
Registered: Feb 2017
Posts: 6

Rep: Reputation: Disabled
Scripting


I've just started a class on scripting and have run into a wall. Can anyone help/hint with this?

Write a shell script to ask for name, major, and expected graduation year. The output should be split onto 3 lines.

Write a shell script to find the sum, the average, and the product of 4 integers entered by the user. The output should be split onto 3 lines


Write a shell script to check whether or not the provided year is a leap year. The output should be the word yes or no

Write a shell script to display all usernames that contains a given pattern of characters. You will need to use the cut and grep commands against the /etc/passwd file to do this.
 
Old 02-17-2017, 12:47 PM   #2
jkirchner
Member
 
Registered: Apr 2007
Location: West Virginia
Distribution: Ubuntu
Posts: 977

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
They won't help do your homework for you (see the LQ rules about homework/classwork). You need to post what you have tried using the code tags too to make it readable.

I see you have lots of these questions. posting search.
 
Old 02-17-2017, 01:09 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,894
Blog Entries: 13

Rep: Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945
jkirchner is correct in noting that LQ members are not here to be your "on call" support team.

This also was cited in your former question on the topic of scripting.

Below is a cut and paste from the LQ Welcome link, as well as a reminder about the LQ Rules
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.
Hello and welcome to LQ. You were pointed here because a fellow LQ member feels the thread you started doesn't contain enough information to enable us to help you. We understand that Linux can be intimidating for new members, and we really do want to help. That said, please understand that LQ is not a help desk, customer service line for a product you purchased or willing to do your homework (although we are happy to assist you with specifics, if you show some effort of your own!). We're a 100% volunteer organization that wants to help you help yourself.

Here are a couple tips that will enable us to help you moving forward:

When asking a question, be sure to provide as many relevant details as possible. You should include the distribution and version you're using, along with hardware details, application version and exact error messages where applicable.
Using a descriptive title will vastly increase the number of members who see your thread, and therefore make a response significantly more likely.
If you're actively troubleshooting an issue you should also include any steps you've already taken.
You may want to include how what you are experiencing differs from what you expected to experience.
Before posting, have you used the search function to ensure your question hasn't been asked before?
You can edit your post by clicking the EDIT button in the bottom right corner of your message.

If you are unwilling or unable to ask questions in a manner that allows us to help you, it's unlikely our community will be able to provide you a solution. Unfortunately, serial offenders who show wanton disregard for this request after multiple pointers may be asked to seek help elsewhere. We truly hope that isn't necessary, and assure you Linux and Open Source are extremely rewarding and well worth the learning curve in the long run.

Some additional reading that may help:
LQ Search
LQ Sitemap
LQ Site FAQ
How to ask technical questions to get quality answers
 
Old 02-18-2017, 10:24 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,186

Rep: Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064
Quote:
Originally Posted by Ziggy2017 View Post
I've just started a class on scripting and have run into a wall. Can anyone help/hint with this?

Write a shell script to ask for name, major, and expected graduation year. The output should be split onto 3 lines.
Write a shell script to find the sum, the average, and the product of 4 integers entered by the user. The output should be split onto 3 lines
Write a shell script to check whether or not the provided year is a leap year. The output should be the word yes or no
Write a shell script to display all usernames that contains a given pattern of characters. You will need to use the cut and grep commands against the /etc/passwd file to do this.
This sounds familiar:
http://www.linuxquestions.org/questi...ng-4175598825/
 
Old 02-19-2017, 03:23 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Show us your work.
 
Old 02-19-2017, 03:35 PM   #6
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Too mean, removed.

Last edited by dijetlo; 02-19-2017 at 03:47 PM.
 
Old 02-19-2017, 03:53 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,186

Rep: Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064
Quote:
Originally Posted by dijetlo View Post
Too mean, removed.
Feh...I liked the original idea.
 
Old 02-20-2017, 08:53 AM   #8
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Well, I think we both know there's no education in the second kick of a mule.
If the OP continues on like this, he'll discover soon enough the error of his ways, moments after his boss in all likelihood.

Last edited by dijetlo; 02-20-2017 at 09:22 AM.
 
Old 02-20-2017, 09:20 AM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
best way to figure out a script in writing it is, one step at a time. Lets look at all of the steps you will be needing to do to get a complete script to do what you need it to do.

1.
Quote:
input needs:
name
major
expected graduation year

output needs:
print to screen
should be split onto 3 lines
input
http://tldp.org/LDP/Bash-Beginners-G...ect_08_02.html
output
https://www.cyberciti.biz/faq/how-to...t-to-terminal/
math
http://faculty.salina.k-state.edu/ti...bash/math.html

another separate script, or within the same one. Does not matter really, just need to have it do one first then the next.
2.
Quote:
input:
4 integers

output:
print to screen
sum of 4 integers
average of 4 integers
split into 3 lines off of two outputs, does not compute.
another script or within the same script.
3.
Quote:
function:
return yes|no if input year is a leap year or not

print to screen
another script or within the same script.
4.
Quote:
function that writes to screen all usernames that contain a given pattern
using characters, by means of cut and grep. Data to use is /etc/passwd (file)

print to screen
grep
https://www.cyberciti.biz/faq/howto-...in-linux-unix/
cut
http://www.computerhope.com/unix/ucut.htm

that is a lot of homework you want to take credit for others doing the work for you. Do you not think?

Remember what I said in the beginning of this post, take it one step at a time.
rule of thumb:
if you can do it in the command line then it can be done in a script.

the use of a function is my take on it, not the teachers. He or she may or may not like the student showing any kind of initiative.

Function
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-8.html



Bonus Points:
leap year
http://www.programmingunit.com/2013/...eck-leap-year/

you'd be surprised what one can find out on the internet now days.

Last edited by BW-userx; 02-20-2017 at 09:52 AM.
 
Old 02-20-2017, 10:42 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I can literally google each sentence starting with "Write a shell script to " in the Opening Post and find answers and examples.
 
Old 02-20-2017, 10:53 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Habitual View Post
I can literally google each sentence starting with "Write a shell script to " in the Opening Post and find answers and examples.
that just makes me wonder where the teacher got his homework assignments to give out from.

I got them all done by hand myself. Last two in functions leap year and the grep + cut = user names

all 4 in the same script.


what happen to that OP?

Last edited by BW-userx; 02-20-2017 at 11:13 AM.
 
  


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
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 08:03 AM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
scripting help wedgeworth Linux - Software 10 09-25-2003 01:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:16 PM.

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
Open Source Consulting | Domain Registration