LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-10-2012, 05:01 PM   #1
sarahm
LQ Newbie
 
Registered: May 2012
Posts: 5

Rep: Reputation: Disabled
Unhappy 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
 
Old 05-10-2012, 05:07 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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})
 
Old 05-10-2012, 05:29 PM   #3
sarahm
LQ Newbie
 
Registered: May 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
the user is suppose to enter the information and it should look like a table with 4 columns (Id , name, sex, total hours)
 
Old 05-10-2012, 05:37 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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?
 
Old 05-10-2012, 06:09 PM   #5
sarahm
LQ Newbie
 
Registered: May 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
yes, on the command line and i'm not really sure if i should use the bash script, but most likely,yes
 
Old 05-10-2012, 06:24 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
Old 05-10-2012, 06:48 PM   #7
sarahm
LQ Newbie
 
Registered: May 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
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..
 
Old 05-10-2012, 06:53 PM   #8
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
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
 
Old 05-10-2012, 07:04 PM   #9
sarahm
LQ Newbie
 
Registered: May 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
I'm sure the links and notes will help me, thx a lotttt Chris...
 
Old 05-11-2012, 03:00 PM   #10
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
Old 05-11-2012, 03:15 PM   #11
Seham
LQ Newbie
 
Registered: May 2012
Posts: 1

Rep: Reputation: Disabled
can any one write the full code please?
 
Old 05-11-2012, 04:36 PM   #12
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
  


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
Microsoft Store employees have to dance? newbiesforever General 6 11-24-2009 09:55 PM
seperate visitors from employees on network blckspder Linux - Security 4 10-10-2008 09:06 AM
Ratio of male to female comp. geeks DanTaylor General 20 05-14-2006 10:17 AM
Microsoft employees using Linux pixellany General 11 01-23-2006 10:21 AM
if someone's first name is aninda, are they male of female? 0pal_t0ad General 17 08-10-2005 04:06 PM


All times are GMT -5. The time now is 02:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration