Help edit simple payroll script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help edit simple payroll script?
# 1  
Old 05-28-2008
Question Help edit simple payroll script?

I'm trying to write a simple script to figure pay with overtime...I got the first part to work, but I can't seem to get the second if statement's syntax right...SmilieI want it to take the 40 hours times 10 dollars, but then i want whatever is left over (like 7 of 47 hours) and take that times 15 dollars and then add the two figures...here's what I've got:
Code:
#!/bin/bash
# Script for figuring pay with overtime
# 5/28/08
hours=$1
normal=10
over=15
ntimepay=400
time=40
if [ $hours -le 40 ]
then
        pay=$[$hours*$normal]
        else
                if [ $hours -gt 40 ]
                then
                pay=$[expr $ntimepay + [$hours-$time]*$over]
                fi
fi
echo "Total pay is $pay"
echo "done"

Any help would be greatly appreciated! Thanks!Smilie

Last edited by Yogesh Sawant; 05-28-2008 at 02:26 AM.. Reason: added code tags
# 2  
Old 05-29-2008
I'd suggest you use modulo arithmatic here via expr:
Code:
...
leftover=`expr $hours % $time`
basepay=`expr $hours - $leftover '*' $normal`
overpay=`expr $leftover '*' $over
pay=`expr $basepay + $overpay`
...

(Untested)
# 3  
Old 05-30-2008
Tested Smilie
Code:
#!/bin/sh
test $1 -gt 40 && echo $(( $1 % 40 * 15 + 40 * 10 )) || echo $(( $1 * 10 ))


Last edited by danmero; 05-30-2008 at 02:53 AM.. Reason: Make life complicated
# 4  
Old 05-30-2008
Quote:
Originally Posted by danmero
Tested Smilie
Code:
!/bin/sh
    echo $(( $1 % 40 '*' $o + 40 '*' $r ))

Does $(()) work in sh?
# 5  
Old 05-30-2008
You can try Smilie
# 6  
Old 05-30-2008
Sounds like a Linux thing. /bin/sh -> /bin/bash.

Then bash pretends it's sh, but it doesn't do a great job.
# 7  
Old 05-30-2008
#!/bin/bash
# Script for figuring pay with overtime
# 5/28/08
hours=$1
normal=10
over=15
ntimepay=400
time=40
if [ $hours -le 40 ]
then
pay=`expr $hours \* $normal`
else
xtime=`expr $hours - $time`
pay=`expr $ntimepay + $xtime \* $over`
fi
echo "Total pay is $pay"
echo "done"





Quote:
Originally Posted by miss72006
I'm trying to write a simple script to figure pay with overtime...I got the first part to work, but I can't seem to get the second if statement's syntax right...SmilieI want it to take the 40 hours times 10 dollars, but then i want whatever is left over (like 7 of 47 hours) and take that times 15 dollars and then add the two figures...here's what I've got:
Code:
#!/bin/bash
# Script for figuring pay with overtime
# 5/28/08
hours=$1
normal=10
over=15
ntimepay=400
time=40
if [ $hours -le 40 ]
then
        pay=$[$hours*$normal]
        else
                if [ $hours -gt 40 ]
                then
                pay=$[expr $ntimepay + [$hours-$time]*$over]
                fi
fi
echo "Total pay is $pay"
echo "done"

Any help would be greatly appreciated! Thanks!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

File edit script exceptions how to pass to script

i wrote script for if file exists script do file edit problem with the script get stuck not existing as for exit i mentioned exit 0 , and how to give the exception for script it should add ./script -- add hi ./script --add "hi how are you" now below script with case it is working for... (0 Replies)
Discussion started by: markjohn1
0 Replies

2. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

3. Shell Programming and Scripting

Script to make simple recurring ascii file edit

Hi, I have an ascii file with recurring lines (the file is 36mb so lots of lines) which look like this: -2.5 -66.324-68.138 935.2 1.953 -0.664 272.617 73.684 -2.428 269.998 0.000 Every 14 lines there is a blank line. I would like to, for each non-blank line,... (2 Replies)
Discussion started by: blueade7
2 Replies

4. Shell Programming and Scripting

Need help in a shell script to edit a tablespace creation script.

Hi, CREATE TABLESPACE aps_blob_large01 DATAFILE '/c2r6u13/u03/oradata/qnoldv01/aps_blob_large0101.dbf' SIZE X 270532608 REUSE DEFAULT STORAGE (INITIAL 134217728 NEXT... (2 Replies)
Discussion started by: rparavastu
2 Replies

5. Shell Programming and Scripting

HP-ux: Script edit

Hallo Friends, I have written a script which goes through different directories deleting files but I think there is a shorter way I can do this please help. #!/bin/ksh #set -x cd /minotaur/Data/CFD_Input/E_CIF cd 051 for files in 2008* do rm -rf $file done # cd ../052 for... (3 Replies)
Discussion started by: kekanap
3 Replies

6. Shell Programming and Scripting

How to EDIT file using VI in a script

Hello, How would i go about editing a file using VI within a shell script please? Basically, i want to open a file, clear it's contents and save the file. I found this on the web using "ex" but can't seem to get it to work: ex /home/oconnor/TOOLS/UNIXCMDS/test_ex <<eof_ex dd /*i put... (2 Replies)
Discussion started by: bobk544
2 Replies

7. Shell Programming and Scripting

Simple SED edit

I have output like the following: B D 20070116095820001 N D S0000579.LOG S0000582.LOG B D 20070116095750001 N D S0000574.LOG S0000576.LOG B D 20070116095734001 N D S0000570.LOG S0000573.LOG B D 20070116095705001 N D S0000569.LOG S0000569.LOG B D ... (5 Replies)
Discussion started by: rdudejr
5 Replies

8. UNIX for Dummies Questions & Answers

simple file edit

What command can I use to simply edit a file by searching for a word and then deleting the lines that I find that word in? (4 Replies)
Discussion started by: capesong
4 Replies
Login or Register to Ask a Question