Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When i run

while [ $p \< 1 ]
    echo $p
    p=$(echo "scale=2; $p*$k" | bc)

i have this result


What can i do to have 0.1, 0.2, 0.4 and 0.8 ?

share|improve this question

closed as off topic by Rinzwind, hhlp, LnxSlck, Jorge Castro, Tachyons Nov 20 '12 at 18:47

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Before the echo check with an if if the 1st char of p is a point and if so add a 0 in front of it? – Rinzwind Nov 20 '12 at 15:36
this is a pure programming question and probably belongs on stackoverflow instead... – ImaginaryRobots Nov 20 '12 at 16:17

Use printf instead of echo to format it:

printf %0.1f\\n $p


$ p=0.1; k=2
$ while [ $p \< 1 ]; do     printf %0.1f\\n $p ;     p=$(echo "scale=2; $p*$k" | bc); done
share|improve this answer

I would do use seq and printf to solve my problem. check this:

for i in $(seq .1 .2 1); do printf "%0.1f\n" "$i"; done

Maybe this will help you to continue.

share|improve this answer

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