how to generate random numbers in a shell script?
Brian
reflection at gmail.com
Tue Oct 6 20:20:20 UTC 2009
$(($RANDOM%59))
On Tue, Oct 6, 2009 at 2:14 PM, Eugeneapolinary Ju <
eugeneapolinary81 at yahoo.com> wrote:
> 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<jh%2Bubuntu at daria.co.uk>
> >* wrote:
>
>
> From: Jonathan Hudson <jh+ubuntu at daria.co.uk <jh%2Bubuntu 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<http://mc/compose?to=ubuntu-users@lists.ubuntu.com>
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
>
> --
> 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/bd9f9ac0/attachment.html>
More information about the ubuntu-users
mailing list