LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:08 AM   #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, 11:12 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 11:16 AM   #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, 11:42 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You could use the eval command:

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


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

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


Reply



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 09:09 AM
bash in ubuntu: save the wildcard expansion beebop Programming 0 03-12-2006 01:19 AM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM
Bash Script Expansion Problem meadensi Linux - Newbie 1 03-04-2005 05:17 PM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:56 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration