我有一个包含指数列表的变量:
p=`seq -1 0.25 2`
我想从中获取10的幂列表,并将其分配给另一个变量。在这种情况下,预期结果将是:
0.1, 0.177828, 0.316228, 0.562341, 1., 1.77828, 3.16228, 5.62341,
10., 17.7828, 31.6228, 56.2341, 100.
我该怎么做?
答案 0 :(得分:3)
$ answers=`seq -1 0.25 2 | sed 's/^/e(/; s/$/ * l(10))/' | bc -l`
$ printf '%s\n' $answers
.10000000000000000000
.17782794100389228012
.31622776601683793320
.56234132519034908039
1.00000000000000000000
1.77827941003892280121
3.16227766016837933197
5.62341325190349080387
9.99999999999999999992
17.78279410038922801203
31.62277660168379331945
56.23413251903490803828
99.99999999999999999840
答案 1 :(得分:3)
使用gnu awk你可以这样做:
L=$( LC_ALL=C seq -1 0.25 2 | awk '{print 10**$1}' )
echo $L
> 0.1 0.177828 0.316228 0.562341 1 1.77828 3.16228 5.62341 10 17.7828 31.6228 56.2341 100
(由于我的区域设置,我需要LC_ALL=C
。)