PDA

Bekijk de volledige versie : sh scripting add numbers of string



dyonisos
31-07-2010, 13:59
Please help sh scripting experts.
I want to add the numbers in a string as follows
signal="0 1 1 0"
meaning 0+1+1+0
and ouput the result in a new variable. Thanks a lot.
I am using my wl-500gP with the Velleman board reading digital inputs.

wpte
31-07-2010, 16:26
not that hard, bash has some pretty standard string manipulation tools:)

with "expr length" you can retrieve the length of a string
and with substring you can take a part of a string to use:)

http://tldp.org/LDP/abs/html/string-manipulation.html
Look at the example scripts and you'll see how to use them;)

dyonisos
31-07-2010, 21:01
Thanks, wpte.
Unfortunately the proposed link does not work. Please advice.
dyonisos