I have an initial record 0.018
I would like a script that would for i=0;i<200;i++ print
0.018*1
0.018*2
0.018*3
0.018*4
...
0.018*200
using newline.
I have an initial record 0.018
I would like a script that would for i=0;i<200;i++ print
0.018*1
0.018*2
0.018*3
0.018*4
...
0.018*200
using newline.
Which shell? Try:
for((i=1;i<=200;i++))
do
echo '0.018*'$i
done
Korn shell if it's a bash script.
Also, your script doesn't work for me, I get
*0.018 0
*0.018 1
*0.018 2
*0.018 3
*0.018 4
*0.018 5
*0.018 6
*0.018 7
*0.018 8
*0.018 9
*0.018 10
*0.018 11
*0.018 12
*0.018 13
*0.018 14
*0.018 15
*0.018 16
*0.018 17
*0.018 18
*0.018 19
What was the exact command you typed in?
for((i=1;i<=200;i++))
do
echo '0.018*'$i >> bla
done
with
ksh -x ./script
---------- Post updated at 06:54 AM ---------- Previous update was at 06:52 AM ----------
Ok, but now I get
0.018*1
0.018*2
0.018*3
0.018*4
0.018*5
0.018*6
0.018*7
0.018*8
0.018*9
0.018*10
0.018*11
0.018*12
0.018*13
0.018*14
0.018*15
0.018*16
0.018*17
0.018*18
0.018*19
0.018*20
0.018*21
0.018*22
0.018*23
0.018*24
0.018*25
0.018*26
0.018*27
0.018*28
0.018*29
0.018*30
How could I get the shell to actually evaluate the multiplication,
i.e. desired output
0.018
0.036
...
pass it through either via expr or bc
#!/bin/bash
for((i=1;i<=200;i++))
do
foo=`expr 0.018\*$i`
echo $foo >> bla
done
Gives
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
expr 0.018 \* $i
---------- Post updated at 07:34 AM ---------- Previous update was at 07:15 AM ----------
Ok, this works:
#!/bin/bash
for((i=1;i<=200;i++))
do
echo "0.018 * $i" | bc
done
.018
.036
.054
.072
.090
.108
.126
.144
.162
.180
.198
.216
.234
.252
.270
.288
.306
.324
.342
.360
.378
.396
.414
.432
.450
.468
.486
.504
.522
.540
expr behaves strange on some OS..
try bc
format it using printf if you expect o/p in specific format..
echo 0.018*$i|bc