.dsy:it.
Show 150 posts per page

.dsy:it. (http://www.dsy.it/forum/)
- Sistemi operativi I (http://www.dsy.it/forum/forumdisplay.php?forumid=269)
-- sommare con la shell di minix una lista di numeri (http://www.dsy.it/forum/showthread.php?threadid=35901)


Posted by jaguaro on 23-07-2008 15:55:

sommare con la shell di minix una lista di numeri

non mi è molto chiaro come fare...
ho fatto un po' di prove con expr, variabili e file ma non sono giunto ad una soluzione..

es.

file numbers
1
43
6
3
87
3
8
5
9


se voglio sommarli?

__________________
Carlo Boni
Rappresentante Studenti
Sinistra Universitaria


Posted by Gehur on 23-07-2008 19:19:

http://www.dsy.it/forum/showthread....5&pagenumber=22

solo che se stampo sum mi visualizza:

esempio fatto con sum=0 e tmp=1234

0+1
0+2
0+3
0+4

e non mi fa la somma


Posted by Gehur on 23-07-2008 19:37:

ecco..


Posted by ideafix on 23-07-2008 20:22:

ho avuto lo steso problema è solo un problema di spazii!!!

se invece di

S=$(expr $S+$N)

scrivi

S=$(expr $S + $N) funziona :|


Posted by Gehur on 23-07-2008 20:34:

ok grazie


Posted by jaguaro on 23-07-2008 21:48:

Grazie mille davvero!
non avevo pensato al cat nel in del for!

la riassumo qua per velocità di lettura dei posteri:

code:
#!/bin/sh sum=0 for tmp in $(cat numbers); do sum=$(expr $sum + $tmp); echo $sum; done

__________________
Carlo Boni
Rappresentante Studenti
Sinistra Universitaria


All times are GMT. The time now is 04:52.
Show all 6 posts from this thread on one page

Powered by: vBulletin Version 2.3.1
Copyright © Jelsoft Enterprises Limited 2000 - 2002.