我想将 2^500 的值存储在变量中DELTA
。
我正在做
export DELTA=$(echo "scale=2; 2^500" | bc)
但这并没有设置DELTA
为3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
.相反,它将其设置为
32733906078961418700131896968275991522166420460430647894832913680961\
33796404674554883270092325904157150886684127560071009217256545885393\
053328527589376
我尝试了以下答案这个问题(3岁),使用
export DELTA=$(echo "scale=2; 2^500" | bc | tr '\n' ' ')
或者
export DELTA=$(echo "scale=2; print 2^500" | bc | tr '\n' ' ')
但它们都不能用于设置变量,只能回显它。任何想法?
答案1
在 的 GNU 实现中bc
,有一个环境变量BC_LINE_LENGTH
(cf man bc
):
~$ echo "scale=2; 2^500" | bc
32733906078961418700131896968275991522166420460430647894832913680961\
33796404674554883270092325904157150886684127560071009217256545885393\
053328527589376
~$ export BC_LINE_LENGTH=99999 #or better 0
~$ echo "scale=2; 2^500" | bc
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
答案2
echo "scale=2; 2^500" | bc | tr -d '\n\\'
输出:
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009 217256545885393053328527589376
答案3
外箱思考:
export DELTA=$(python -c 'print(2**500)')
答案4
$ echo "scale=2; 2^500" | bc | perl -pe 's/\\\n//'
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376