0

Here is my script:

#!/bin/bash
nb_lines=30
expr 100 / $nb_lines

./test1.sh 
3

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

1 Answer 1

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .