Computer Hope

Software => BSD, Linux, and Unix => Topic started by: roohi on November 28, 2011, 01:46:09 AM

Title: how to remove varible from a list
Post 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
Title: Re: how to remove varible from a list
Post by: roohi on December 01, 2011, 10:53:59 PM

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 :

Code: [Select]
var1=$(echo $var1 | sed "s/$var//")
But still How can i select the random varible from the list Question is there.
Please suggest.
Title: Re: how to remove varible from a list
Post by: roohi on December 01, 2011, 11:27:39 PM
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