shell script to seperate male employees from female employees
Linux - NewbieThis 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.
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.
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
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})
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.