I'm trying to get a random character print out in an array that is stored with characters. I'm new to bash and been looking at some guides along the way but have run into a bit of a problem.
I create an array to test with which stores chars. I then have a variable called Range which is 21 (this is the length of the array).
#create an characters to test with
letters=(a,b,e,g,i,j,k,l,m,n,p,q,r,s,t,u,v,y,x,w,z)
RANGE=21
I then try and get a random number from 0 -> range, so it will correspond with array indices. I then need to access the array index of the random number and store that in a variable called arraychar. I have done it like this:
number=$RANDOM%$RANGE #gets int of a random number between 0 and range (size of array)
arraychar=${letters[$number]} #chooses a random char from array and stores in arraychar
Then I want to pass this letter as an argument to my executable like so:
for i in `seq 1 3`;do
echo $i " "
./sample-tree -$arraychar
done
It keeps hanging here, and I'm not too sure what's it doing, and why it isn't working.
Any help would be appreciated as I'm a newbie!
Thanks.
letters=({a..z})syntax also works (at least on bash 4..)