Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.
#!/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"
share|improve this question

closed as off-topic by Costas, G-Man, Anthon, Ramesh, cuonglm Aug 18 at 16:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – G-Man, Ramesh, cuonglm
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Hi 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 at 12:33
2  
possible duplicate of basic division using variable and integer –  Fiximan Aug 18 at 12:42
    
da=$((( basic + dp ) * 35 / 100)) and so on –  Costas Aug 18 at 12:43

1 Answer 1

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.

share|improve this answer
    
@sardar, please read unix.stackexchange.com/help/someone-answers –  glenn jackman Aug 18 at 14:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.