With a "normal" (i mean "full") linux distro, it works just fine:

sleep $(echo "$[ ($RANDOM % 10 ) ]")

ok, it waits for about 0-9 sec

but under OpenWRT [not using bash, rather "ash"]:

$ sleep $(echo "$[ ($RANDOM % 9 ) ]") sleep: invalid number '$[' $

and why:

$ echo "$[ ($RANDOM % 9 ) ]" $[ ( % 9 ) ] $

So does anyone has a way to generate random numbers under OpenWRT, so i can put it in the "sleep"?

Thank you

link|improve this question

62% accept rate
ash isn't bash; you can't use bash features with it. – Ignacio Vazquez-Abrams Jan 13 '11 at 0:10
@user62367 someone from SO has already answer your question. – Victor T. Jan 13 '11 at 11:52
Seriously, stop crossposting. – Wuffers Feb 5 '11 at 15:41
feedback

2 Answers

Ash doesn't understand $[] and it's deprecated in Bash. Also, the echo is unnecessary. Use this instead for both Bash and Ash:

sleep $(( $RANDOM % 10 ))
link|improve this answer
feedback
up vote 0 down vote accepted

generate max 3 digit number: 0-999 sleep $(head -30 /dev/urandom | tr -dc "0123456789" | head -c3)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.