how to generate random numbers in a shell script?

Jonathan Hudson jh+ubuntu at daria.co.uk
Tue Oct 6 19:29:43 UTC 2009


On Tue, 6 Oct 2009 12:16:09 -0700 (PDT), Eugeneapolinary Ju wrote:

># something=$[ ($RANDOM % 59 ) ] 
># echo $something
>29
>
>
>ok, but if I put it in a script:
>
># echo -e '#!/bin/bash\nsomething=$[ ($RANDOM % 59 ) ]'>test.sh
>
># cat test.sh 
>#!/bin/bash
>something=$[ ($RANDOM % 59 ) ]
>
># sh test.sh 
>test.sh: 2: Syntax error: "(" unexpected
>
>
>
>Why??
>
>Thank you! :S
>
>
>      

bash ain't sh







More information about the ubuntu-users mailing list