Addition in bash

Tony Arnold tony.arnold at manchester.ac.uk
Wed Oct 14 17:48:28 UTC 2009


Ray,

Ray Parrish wrote:
> Hello,
> 
> I have the following script fragment
> 
> Seconds=0;
> while [ "$Seconds" -lt "60" ]
>   do
>   sleep 5;
>   Seconds=$Seconds+5;
>   padsp espeak "$Seconds"
> done
> 
> For some reason Seconds becomes "0+5" instead of the integer value 5 
> which is what I am attempting to get it to be.
> 
> Does anyone know how to do integer math in bash?

Yes, use the let command. So replace:

	seconds=$second+5

with

	let seconds=$seconds+5

HTH.

Regards,
Tony.
-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 870 136 1004
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk




More information about the ubuntu-users mailing list