PDA

View Full Version : bash script oddity with $RANDOM returning null



bsautner
August 10th, 2011, 06:30 PM
This is really weird and probably has a simple fix but check this out - driving me crazy

Ubuntu 11.04 in a terminal i type

$echo $RANDOM

I get a random number as expected.

I create a bash script ($vi script.sh):

#!/bin/bash
echo $RANDOM

do a chmod a+x on it

run sh ./script.sh

and i get en empty response - i.e as if $RANDOM returned a null or empty string or something. In any case where i use $RANDOM in a bash script it returns empty but it works on the command line... thoughts!? I'm missing something here.

sisco311
August 10th, 2011, 06:36 PM
In Ubuntu sh is s symlink to dash. ;)

bsautner
August 10th, 2011, 06:38 PM
ohhhhh i must delete this thread out of shame. ok running my scripts without the sh works fine. Great googly moogly thank you.

sisco311
August 10th, 2011, 06:40 PM
No problem.