Here is my script:

expr 100 / $nb_lines


1) How can i change this script to have '3.33333333' ? Variable 1

2) How can i change this script to have '4' (round superior) ? Variable 2


expr is only capable of integer arithmetic so it will never return you any fraction value.

To be able to use floating point calculations, you should get acquainted with some simple shell tool that can be utilized for that purpose such as

  • bc - An arbitrary precision calculator language or
  • gawk - pattern scanning and processing language

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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