1

Here is the part that generates the 10 random numbers.

MAXCOUNT=10
count=1

while [ "$count" -le $MAXCOUNT ]; do
 number=$RANDOM
 let "count += 1"
done

Now how do I output this to an array and then echo that array?

3
  • Why don't you print them immediately?
    – cuonglm
    Nov 28, 2015 at 5:49
  • Because this is a school exercise and I'm still trying to figure out how to do things. Otherwise echoing them right away does make sense. Nov 28, 2015 at 5:50
  • Smells like homework ;) Nov 28, 2015 at 7:56

1 Answer 1

3

Are you using bash? In that case, try something like that:

MAXCOUNT=10
count=1

while [ "$count" -le $MAXCOUNT ]; do
 number[$count]=$RANDOM
 let "count += 1"
done

echo "${number[*]}"

You can also replace the last line with:

echo "${number[@]}"

Some documentation here: http://www.tutorialspoint.com/unix/unix-using-arrays.htm

2
  • This is exactly what I was trying to do thanks! Nov 28, 2015 at 5:49
  • Why not number[]=$RANDOM instead of number[$count]=$RANDOM? Nov 28, 2015 at 7:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .