-1
#!/bin/ksh

a=8.3
b=10.20
diff=`expr $b - $a`
echo "$diff"

its giving

expr: 0402-046 A specified operator requires numeric parameters. error i want output as 1.9

3
  • you could use bc instead : echo $b-$a | bc. On the command line expr 3.2 - 2 gives the same result. It seems that expr can't take float: see unix.stackexchange.com/questions/165165/… Commented Dec 9, 2016 at 11:58
  • @Giri: You can provide feedback on the provided answer and accept it ( a small tick mark on left of the answer) to mark the post resolved. Commented Dec 12, 2016 at 5:54
  • As per the remarks added by a helpful person to your later question here, we do expect you to interact with people who assist you. I have upvoted the post below, and downvoted your post. Commented Dec 23, 2016 at 22:55

1 Answer 1

1

You don't need bc for this, use the native arithmetic operators in ksh

#!/bin/ksh

a=8.3
b=10.20
printf "%.2f\n" "$((b - a))"

outputs

$ ksh script.ksh
1.90
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.