1.

Solve : duplicate : how to remove varible from a list?

Answer»

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 ?
I am using unix shell scripting

Thanks
RG
   
hey I am doing something like following:

CODE: [Select]var1='1 2 3 4 5'

for var in $var1 {Need to choose the variable randomly used rand($var1) but its not working }
Code: [Select]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 ?
I am using unix shell scripting

Thanks
RG
Quote from: roohi on November 28, 2011, 01:46:09 AM


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.make an array of variable in list , find the index of that array .
Do Code: [Select]X=rand()%index to generate the random number and with that random number go to the array element : Code: [Select]array [x]
This will give you the random selection for each time.

Thanks
RGhello i dont know which language you are working on...but from my experience..

are the syntax correct?


u declare
var1='1 2 3 4 5'

then u said
for var in $var1

i think you should declare var1 as $var1='1 2 3 4 5'

and for $var in $var1





Discussion

No Comment Found