The UNIX and Linux Forums  
Olá e boas-vindas de Estados Unidos para o UNIX e Linux Forum! Obrigado por visitar e fazer parte da nossa comunidade global.

Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
google unix.com



Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui.

Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
Fio Thread Starter Fórum Respostas Última postagem
Como atribuir o valor específico ryanW Programação Shell Script e 4 04-20-2009 10:20
Atribuir o / p de awk para uma variável c2b2 Programação Shell Script e 8 04-01-2009 07:50
como atribuir o primeiro dia do próximo mês Rosalinda Programação Shell Script e 6 07-05-2008 04:13
Atribuir variáveis com corte douknownam Programação Shell Script e 2 09-27-2004 09:18
atribuir a variável AkumaTay UNIX para Dummies Perguntas & Respostas 1 05-18-2002 02:11

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
Linkback Thread Tools Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
navjinder navjinder is offline
Usuário
  
 

Join Date: Apr 2009
Posts: 2
Exclamation Usando o bc para atribuir valor

Amigos aqui o código que é utilizado para adicionar ponto flutuante usando bc, mas eu não estou recebendo nenhuma saída vez alguns erros.

Código:
1 #!/bin/bash

 
  4 if [ -c /proc/$$/fd/0 ]
  5 then
  6    echo "Our input is from a Device"
  7         while read myline
  8         do
  9
 10         total= `echo $total + $myline |bc`
 11         #((total=$total+ $myline))
 12         done
 13
 14 elif [ -p /proc/$$/fd/0 ]
 15 then
 16
 17    echo "Our input is from a pipe"
 18         while read myline2
 19         do
 20         total= `echo $total + $myline |bc`
 21         #((total= $total+ $myline2))
 22         done
 23 elif [ -f /proc/$$/fd/0 ]
 24 then
 25
 26    echo "Our input is from a file"
 27         while read myline3
 28         do
 29         add=+
 30         $(($total $add $myline))| bc
 31         #echo $total $myline
 32         #total= echo `$total $add $myline |bc`
 33         #((total= $total+ $myline))
 34         done
 35
 36
37
38   echo "Error"
 39         break;
 40 fi
 41
 42 echo total is $total

Última edição por Franklin52; em 04/25/2009 09:00.. Motivo: adicionar código tags
  #2 (permalink)  
Old 04-25-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Usuário
  
 

Join Date: Apr 2009
Posts: 521
Talvez algo parecido com isto:

Código:
$ 
$ # display the file "num" that has floating-point numbers, one per line
$                                                                    
$ cat num                                                            
2.1                                                                  
3.4                                                                  
4.6                                                                  
5.2                                                                  
6.3                                                                  
$
$ # display the script
$
$ cat test_scr.sh
#!/bin/bash
NUMFILE=$1
total=0
if [ -c $NUMFILE ]
then
  echo "Our input is from a Device"
  while read LINE; do
    total= `echo $total + $LINE | bc`
  done < $NUMFILE
elif [ -p $NUMFILE ]
then
  echo "Our input is from a pipe"
  while read LINE; do
    total= `echo $total + $LINE | bc`
  done < $NUMFILE
elif [ -f $NUMFILE ]
then
  echo "Our input is from a file"
  while read LINE; do
    total=`echo $total + $LINE | bc`
  done < $NUMFILE
fi
echo total is $total
$
$ # test the script, passing "num" as input
$
$ . test_scr.sh num
Our input is from a file
total is 21.6
$
$
HTH,
tyler_durden
  #3 (permalink)  
Old 04-28-2009
navjinder navjinder is offline
Usuário
  
 

Join Date: Apr 2009
Posts: 2
Thumbs up

Graças tyler_durden. Um bom trabalho feito, sim, faz mais sentido obrigado novamente
Closed Thread

Marcadores

Tags
adicionando, atribuindo valores, bc

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 11:37.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0