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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
05-10-2012, 04:01 PM
|
#1
|
LQ Newbie
Registered: May 2012
Posts: 5
Rep: 
|
shell script to seperate male employees from female employees
Write shell script to enter the information of company employees until the user enter 0 for employee’s id .The information is
(Id , name , sex (M, F) , total hour worked in a month)The script will list the information of all Males employees and females’ employees in two separate files named Males and Females and the total number of Males and total number of Females with average total hours worked for each with final result message ex. “The productive of males is better” or “The productive of females is better”.
I just started using linux and all i came up with is this
-record (employee, {id, name, sex, total-hours})
and i'm not even sure of it
|
|
|
05-10-2012, 04:07 PM
|
#2
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
Sounds like a homework assignment here. So in order to point you in the right direction so you can get this done we will need some more info.
Your script will read data, test it, and then output based upon the results of that test. Is the data going to be read from a flat file or will the user be prompted to enter this information into the script and have it be stored as variables?
If its a flat file what is the structure of the file, is it comma delimited, space, etc..
Not sure what this is: -record (employee, {id, name, sex, total-hours})
|
|
|
05-10-2012, 04:29 PM
|
#3
|
LQ Newbie
Registered: May 2012
Posts: 5
Original Poster
Rep: 
|
the user is suppose to enter the information and it should look like a table with 4 columns (Id , name, sex, total hours)
|
|
|
05-10-2012, 04:37 PM
|
#4
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
And the user is entering this information on the command line correct? Have you made any progress besides the one line posted above?
Also are you going to be coding this in a bash script or some other language?
|
|
|
05-10-2012, 05:09 PM
|
#5
|
LQ Newbie
Registered: May 2012
Posts: 5
Original Poster
Rep: 
|
yes, on the command line and i'm not really sure if i should use the bash script, but most likely,yes
|
|
|
05-10-2012, 05:24 PM
|
#6
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
I'll help you out here do you mind telling me if this is a homework assignment(I will still help you if it is). If this is homework I'll go into more depth and give you so good links to bookmark for future reference.
I use the analogize Linux to being a Chef quite often. Anyone who owns a betty crocker book can become a decent chef, similary in Linux if you know where your resources are and how to read them you can become a decent Linux scripter/user/admin.
|
|
|
05-10-2012, 05:48 PM
|
#7
|
LQ Newbie
Registered: May 2012
Posts: 5
Original Poster
Rep: 
|
it's a bonus question ...like if i did it, then it'll be great and if not, it'll be fine
but i really wanna know how to do it..
|
|
|
05-10-2012, 05:53 PM
|
#8
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434
|
You'll want some good bash reference material.
Here's a good tutorial
http://rute.2038bug.com/index.html.gz
Ref/tutorials on each cmd by example
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
Notes:
1. do put the cmds into a file aka bash shell script file
2. have a good look at the 'read' cmd
3. when you've got something, if you get stuck, post it here and explain what issues you are having.
4. for debugging, add 'set -xv' near the top of your script eg
Code:
#!/bin/bash
set -xv
Good Luck & welcome to LQ 
|
|
|
05-10-2012, 06:04 PM
|
#9
|
LQ Newbie
Registered: May 2012
Posts: 5
Original Poster
Rep: 
|
I'm sure the links and notes will help me, thx a lotttt Chris...
|
|
|
05-11-2012, 02:00 PM
|
#10
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
Those are some great links to have. Chrism01 also gave you a good starting point. I'll give you a small snippet of one of my own codes here that reads a value and stores it as a variable as well as tests the variable for the correct type of input. Hopefully this will give you an idea of what you're trying to accomplish.
Code:
echo "Please enter the number of employees to enter" #Print output to the user asking them a question
read NUMUSERS #The user provides standard input to the script via a keyboard response. This gets stored a variable.
# Now you have a response from a user you can now modify or test that input.
# The below statement will test the users input to verify it is only digits. The != means does not equal
if [[ "$NUMUSERS" != *[[:digit:]]* ]]
then
echo "Please enter only a number for the number of Employees."
exit 1
# An exit of one is a standard exit code for an error with a script.The exit code 0 means it completed successfully.
fi
echo "You choose to create $NUMUSERS users. You will now be asked for their information"
This is where you can continue to echo statements to the user, store their info as variables and then re-print it at the end. You can use if statements like the syntax above if you want to test input. If you really want to learn take a look at writing a while loop for the NUMUSERS variable that will decrease by one each time the user enters in information for a user.
A good link for if statement reference: http://tldp.org/LDP/Bash-Beginners-G...ect_07_01.html
And here's the specific chapter for writing interactive scripts that I would suggest you read before getting started. http://tldp.org/LDP/Bash-Beginners-G...l/chap_08.html
Let us know if you have any specific questions or errors while going through this. Welcome to the wonderful world of Bash.
|
|
|
05-11-2012, 02:15 PM
|
#11
|
LQ Newbie
Registered: May 2012
Posts: 1
Rep: 
|
can any one write the full code please?
|
|
|
05-11-2012, 03:36 PM
|
#12
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
We aren't going to write it for you. Its the old teach a man to fish analogy. Read over the information provided and you should have no problem writing this for yourself. If you get stuck or need info on something specific let us know and we will help you out.
|
|
|
All times are GMT -5. The time now is 05:39 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|