#!/bin/sh
echo "welcome to salary calculator"
echo "Enter basic salary"
read basic
dp=$(( basic / 2 ))
da=$((( basic + dp ) * 35) / 100)
hra=$((( basic + dp ) * 8 )/ 100)
ma=$((( basic + dp ) * 8 ) / 100)
pf=$((( basic + dp ) * 10 ) / 100)
salary=$((((( basic + dp) + da ) + hra ) + ma - pf ))
echo "salary is=$salary"
Asked
Active
Viewed 755 times
-3
-
2Hi sardar, welcome to Unix&Linux stack exchange. Please reformat your script to be readable (e.g. indent by 4 spaces) and expand the content to make it clear what your question is. – steve Aug 18 '15 at 12:33
-
2possible duplicate of [basic division using variable and integer](http://unix.stackexchange.com/questions/103444/basic-division-using-variable-and-integer) – FelixJN Aug 18 '15 at 12:42
-
`da=$((( basic + dp ) * 35 / 100))` and so on – Costas Aug 18 '15 at 12:43
1 Answers
3
You will need to enclose the shell math with $(( ... ))
So the math will need to be:
dp=$(( basic / 2 ))
da=$(( ((basic + dp) * 35 ) / 100 ))
hra=$(( ((basic + dp) * 8 ) / 100 ))
ma=$(( ((basic + dp) * 8 ) / 100 ))
pf=$(( ((basic + dp) * 10 ) / 100 ))
salary=$(( ((((basic + dp ) + da ) + hra) + ma - pf) ))
You may place additional spaces within $(( .. )) to format the lines for readability.
Lambert
- 12,495
- 2
- 26
- 35
-
@sardar, please read http://unix.stackexchange.com/help/someone-answers – glenn jackman Aug 18 '15 at 14:36