Computer Hope
Software => BSD, Linux, and Unix => Topic started by: roohi on November 28, 2011, 01:46:09 AM
-
hey I am doing something like following:
var1='1 2 3 4 5'
for var in $var1 {Need to choose the variable randomly used rand($var1) but its not working }
do
echo $var
done
now as i print the $var i need this value should be removed from the variable $var1, how to do that ?
Thanks
RG
-
var1='1 2 3 4 5'
for var in $var1 {Need to choose the variable randomly used rand($var1) but its not working }
do
echo $var
done
Solve teh problem of by using following :
var1=$(echo $var1 | sed "s/$var//")
But still How can i select the random varible from the list Question is there.
Please suggest.
-
make an array of variable in list , find the index of that array .
Do x=rand()%index to generate the random number and with that random number go to the array element : array
This will give you the random selection for each time.
Thanks
RG