Addition in bash

James Michael Fultz croooow at gmail.com
Wed Oct 14 15:27:36 UTC 2009


* David N. Lombard <dnl at speakeasy.net> [2009-10-14 03:14 -0700]:
> Also, you could do this without arithmetic using
> 
>    for Seconds in $(seq 5 5 60) ; do
>      sleep $Seconds
>      padsp espeak $Seconds
>    done
> 

You can also use a C-like construct with for in Bash.

for (( Seconds = 0; Seconds < 60; Seconds += 5 )) ; do
        sleep $Seconds
        padsp espeak $Seconds
done

> If you really did want sh, Bourne shell, you would do the arithmetic as
> 
>    Seconds=`expr $Seconds + 5`

Most default shells ('/bin/sh') found today are POSIX-compatible so
would support the following.

Seconds=$(( $Seconds + 5 ))




More information about the ubuntu-users mailing list