LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-16-2006, 12:08 PM   #1
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Rep: Reputation: 15
Bash variables expansion


Hi guys,
I'm dealing with a studip problem, as stupid as I can't resolve it

Here's the question.
I have a varible containing the name o a second variable:
Code:
var2="blablabla"
var1='$var2'
echo $var1
give obviously

Code:
$var2
.

The question is, how can I obtain "blablabla" manipulating var1?

thank in advance

olaola
 
Old 10-16-2006, 12:12 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

You don't need the quotes:
var1=$var2

Or if you want/need quotes, use double quotes:
var1="$var2"

In general: All between single quotes is not expanded and all between double quotes is expanded.

Hope this helps.
 
Old 10-16-2006, 12:16 PM   #3
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Original Poster
Rep: Reputation: 15
sorry, maybe my question is not so clear, but I read var1 from a file and is value is exactly $var2 (with dollar symbol)

then I need to extract value of var2 from var1

thank for the answer
 
Old 10-16-2006, 12:42 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

You could use the eval command:

var2="blablabla"
var1='$var2'
echo $var1
eval echo $var1


Hope this helps.
 
Old 10-16-2006, 12:45 PM   #5
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Original Poster
Rep: Reputation: 15
perfect!
thanks a lot!!!
 
  


Reply


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
Variable expansion inside of a bash script! A.S.Q. Linux - Newbie 4 09-29-2006 10:09 AM
bash in ubuntu: save the wildcard expansion beebop Programming 0 03-12-2006 02:19 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 12:31 PM
Bash Script Expansion Problem meadensi Linux - Newbie 1 03-04-2005 06:17 PM
bash script $n variable expansion cortez Programming 6 12-08-2003 05:03 PM


All times are GMT -5. The time now is 08:44 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