Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to remove varible from a list  (Read 3528 times)

0 Members and 1 Guest are viewing this topic.

roohi

    Topic Starter


    Beginner

    how to remove varible from a list
    « 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

    roohi

      Topic Starter


      Beginner

      Re: how to remove varible from a list
      « Reply #1 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.

      roohi

        Topic Starter


        Beginner

        Re: how to remove varible from a list
        « Reply #2 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