how to generate random numbers in a shell script?

Eugeneapolinary Ju eugeneapolinary81 at yahoo.com
Tue Oct 6 20:14:54 UTC 2009


echo -e '#!/bin/sh\nsomething=$[ ($RANDOM % 59 ) ]'>test.sh


# cat test.sh 
#!/bin/sh
something=$[ ($RANDOM % 59 ) ]


# sh test.sh 
test.sh: 2: Syntax error: "(" unexpected

--- On Tue, 10/6/09, Jonathan Hudson <jh+ubuntu at daria.co.uk> wrote:

From: Jonathan Hudson <jh+ubuntu at daria.co.uk>
Subject: Re: how to generate random numbers in a shell script?
To: ubuntu-users at lists.ubuntu.com
Date: Tuesday, October 6, 2009, 7:29 PM

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




-- 
ubuntu-users mailing list
ubuntu-users at lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20091006/f855294a/attachment.html>


More information about the ubuntu-users mailing list