echo "scale=2; 2^500" | bc | tr -d '\n\'
Saída:
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
Eu quero armazenar o valor de 2 ^ 500 na variável DELTA
.
Estou fazendo
export DELTA=$(echo "scale=2; 2^500" | bc)
mas isso não define DELTA
para 3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
. Em vez disso, define para
32733906078961418700131896968275991522166420460430647894832913680961\
33796404674554883270092325904157150886684127560071009217256545885393\
053328527589376
Eu tentei as respostas em esta pergunta (3 anos de idade), usando
export DELTA=$(echo "scale=2; 2^500" | bc | tr '\n' ' ')
ou
export DELTA=$(echo "scale=2; print 2^500" | bc | tr '\n' ' ')
mas nenhum deles trabalha para definir a variável, apenas para ecoar. Alguma idéia?
Na implementação GNU de bc
, existe a variável de ambiente 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
Pensando fora da caixa:
export DELTA=$(python -c 'print(2**500)')
> echo "scale=2; 2^500" | bc | { read value; echo "$value";}
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
$ echo "scale=2; 2^500" | bc | perl -pe 's/\\n//'
3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376