LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   assign vaiables from string values (https://www.linuxquestions.org/questions/programming-9/assign-vaiables-from-string-values-4175454145/)

tsdjim 03-15-2013 02:18 AM

assign vaiables from string values
 
I have this string where the values can be in any order and any number of sets with ='
For example this string:
"bb=also aa=This cc=is dd=a ee=string"

I want to process the string and set the respective variables to the value so that:
$bb=also
$aa=This
$cc=is
$ee=string
$dd=a

chrism01 03-15-2013 02:32 AM

This seems to work for me
Code:

eval  "bb=also aa=This cc=is dd=a ee=string"
echo $bb $aa $cc $dd $ee


tsdjim 03-15-2013 03:08 AM

Thanks Chris. That worked perfectly!

bigearsbilly 03-15-2013 03:19 AM

nice one chrism


All times are GMT -5. The time now is 06:15 PM.