Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
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. –  greatwolf Jan 13 '11 at 11:52
    
Seriously, stop crossposting. –  Wuffers Feb 5 '11 at 15:41
add comment

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 ))
share|improve this answer
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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