LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-15-2013, 02:18 AM   #1
tsdjim
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Rep: Reputation: Disabled
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
 
Old 03-15-2013, 02:32 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
This seems to work for me
Code:
eval  "bb=also aa=This cc=is dd=a ee=string"
echo $bb $aa $cc $dd $ee
 
Old 03-15-2013, 03:08 AM   #3
tsdjim
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks Chris. That worked perfectly!
 
Old 03-15-2013, 03:19 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
nice one chrism
 
  


Reply

Tags
split, variables


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk: sort variable values and assign a name accordingly Trd300 Linux - Newbie 11 03-22-2012 03:55 AM
Python dict query and assign values problems ArthurHuang Programming 2 03-13-2012 04:18 AM
Shell script that assign's values to fields NsearchOf Programming 16 06-01-2009 10:00 AM
C - assign new value to a string error j0hnsmith Programming 4 05-03-2009 11:28 PM
How to assign a string to a structure variable in C? daYz Programming 7 06-13-2007 02:38 PM


All times are GMT -5. The time now is 05:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration