LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-19-2008, 05:44 PM   #1
budhax
LQ Newbie
 
Registered: Aug 2008
Location: Switzerland - GVA
Distribution: BT3
Posts: 8

Rep: Reputation: 0
function showing a list of variable and value: (dynamic variable name)


Hello,
I would like to build a function showing a list of variables like:
variable name : [variable value]
but, respectfully, Mr BASH cannot understand this: ${$name}

Is there a way to do that (using a FOR loop and a list VAR=CN1 ...)?
Thanks

Here my code:

Code:
#^!/bin/bash

fARP=fARP
fCAP=fCAP
fIVS=fIVS
fPSK=fPSK
fXOR=fXOR
#
CN1=eth1
VC1=rtap0
CN2=rausb0
VC2=wifi0
#
RTE=200
MEID=IPW22
DICO=Dic.LOG
IP0=192.168.1.100
IP1=192.168.1.101
MAC=50:41:32:23:14:05
#
VAR="CN1 VC1 CN2 VC2 RTE MEID DICO MAC"

function ShowVAR () {
	echo var_name : [var_value]
	for name in $VAR; do
		value=${$name}
		echo  "$name : $value"
	done
}
 
Old 09-19-2008, 07:05 PM   #2
budhax
LQ Newbie
 
Registered: Aug 2008
Location: Switzerland - GVA
Distribution: BT3
Posts: 8

Original Poster
Rep: Reputation: 0
I found a solution (googleling with: bash dynamic variable name).

Code:
function ShowVAR () {
	echo var_name : [var_value]
	for name in $VAR; do
		#value=${$name}
		echo  "$name : ${!name}"
	done
}
Thanks and regards.

Source:
http://www.commentcamarche.net/forum...bleme-variable
 
  


Reply

Tags
dynamic, name, variable



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
Shell Script and Dynamic variable xanthium Programming 11 07-12-2011 06:05 AM
dynamic variable name in JAVA ufmale Programming 1 07-29-2008 02:48 AM
Bash Shell Scripting Dynamic Variable naming question ZuG Programming 2 02-07-2007 02:39 PM
php function->query(variable) what's that? osio Programming 3 06-12-2006 06:48 AM
PHP Variable = function? wh33t Programming 2 01-22-2005 06:28 AM

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

All times are GMT -5. The time now is 02:52 AM.

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