Sponsored Content
Top Forums Shell Programming and Scripting How to define a variable with variable definition is stored in a variable? Post 302370594 by freddy1228 on Thursday 12th of November 2009 01:22:43 AM
Old 11-12-2009
How to define a variable with variable definition is stored in a variable?

Hi all,

I have a variable say var1 (output from somewhere, which I can't change)which store something like this:

echo $var1

name=fred
age=25
address="123 abc"
password=pass1234

how can I make the variable $name, $age, $address and $password contain the info?

I mean do this in a simple way rather than

for line in $var1
do
varname=`echo $line | cut -f 1 -d '='`
varvalue=`echo $line | cut -f 2 -d '='`
eval $varname=$varvalue
done

I am looking for something like

. $var1 #I know it is wrong

and then...

echo $name # fred
echo $age # 25
echo $address # 123 abc
echo $password #pass1234

I cannot cat $var1 > tmpfile
. tmpfile
rm tmpfile

because the var1 contain sensitive info e.g. password

Thanks a lot!

Last edited by freddy1228; 11-12-2009 at 04:34 AM.. Reason: cannot delete
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using Grep to Define a Variable

I am using korn shell unix. I have a script that I am working with to do a check for me using a text file. #finds "Time" from the text file and cuts the second field from the #line A= grep Time test.txt | cut -f2 # the "#Missing" is being pulled from the second field of the text... (1 Reply)
Discussion started by: cspcspcsp
1 Replies

2. UNIX for Dummies Questions & Answers

define length of variable

I have a variable with a value of "05". When I add one to that variable, using the command: CURR_YY=`expr $CURR_YY + 1`, I get the value of "6", losing the leading zero (which is needed for passing to another script). How do I keep the leading zero? Thank you! (10 Replies)
Discussion started by: cbarker
10 Replies

3. Shell Programming and Scripting

What wrong with the variable definition

i am using the below script and trying to move files in that directory in that pattern to archive. But it doesn;t seem to take the metacharacters. Please sugggest. Code Debug output: (1 Reply)
Discussion started by: dsravan
1 Replies

4. Shell Programming and Scripting

Variable not found error for a variable which is returned from stored procedure

can anyone please help me with this: i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure... ... (4 Replies)
Discussion started by: swap21783
4 Replies

5. Shell Programming and Scripting

question about define variable.

Hi, Unix Gurus, In our existing file, there is a script like #!/bin/sh step=${1:-0} cur_step=10 if ... My question is what's "${1:-0}" mean? I know it defines a variable but I don't know what's (1:-0) mean? :wall: Thanks in advance. (2 Replies)
Discussion started by: ken002
2 Replies

6. Shell Programming and Scripting

Define variable from file.

HI I have file A.txt _1A _2A _3A _4A I want define all as different variable. $1A=_1A $2B=_2A $3C=_3A $4D=_4A Now i can use any variable in my script. (3 Replies)
Discussion started by: pareshkp
3 Replies

7. Shell Programming and Scripting

Getting value of variable whose name is stored in another variable

Unix OS : Linux 2.6x Shell type : Korn I am stuck in weird problem . In my shell script I am setting an environment variable using the following command : EMP="KUMARJIT"; export EMP In the following sections of the script , what I did is : I created and initialized a new shell variable "type"... (5 Replies)
Discussion started by: kumarjt
5 Replies

8. UNIX for Advanced & Expert Users

Variable definition

Hi all, I'm bit new to the advanced bash shell scripting. When I'm looking at some of the existing code in my organization, got confused with a few variable definings. For ex: var1={1:-30} var2="abc def ghi" var3={xyz:-$var2} In above, 1st and last lines are confusing me.... (4 Replies)
Discussion started by: raghu.iv85
4 Replies

9. UNIX for Dummies Questions & Answers

Environment variable definition

I'm a bit confused about the term ‘environment variables'. Within your shell you can set two types of variables: 1. Shell variable - affecting functionality within your shell 2. User defined variable When using the ‘export' command on a variable you make sure it's being inherited by new sub... (2 Replies)
Discussion started by: niels
2 Replies
scope(n)							    [incr Tcl]								  scope(n)

__________________________________________________________________________________________________________________________________________________

NAME
scope - capture the namespace context for a variable SYNOPSIS
itcl::scope name _________________________________________________________________ DESCRIPTION
Creates a scoped value for the specified name, which must be a variable name. If the name is an instance variable, then the scope command returns a string of the following form: @itcl object varName This is recognized in any context as an instance variable belonging to object. So with itcl3.0 and beyond, it is possible to use instance variables in conjunction with widgets. For example, if you have an object with a private variable x, and you can use x in conjunction with the -textvariable option of an entry widget. Before itcl3.0, only common variables could be used in this manner. If the name is not an instance variable, then it must be a common variable or a global variable. In that case, the scope command returns the fully qualified name of the variable, e.g., ::foo::bar::x. If the name is not recognized as a variable, the scope command returns an error. Ordinary variable names refer to variables in the global namespace. A scoped value captures a variable name together with its namespace context in a way that allows it to be referenced properly later. It is needed, for example, to wrap up variable names when a Tk widget is used within a namespace: namespace foo { private variable mode 1 radiobutton .rb1 -text "Mode #1" -variable [scope mode] -value 1 pack .rb1 radiobutton .rb2 -text "Mode #2" -variable [scope mode] -value 2 pack .rb2 } Radiobuttons .rb1 and .rb2 interact via the variable "mode" contained in the namespace "foo". The scope command guarantees this by return- ing the fully qualified variable name ::foo::mode. You should never use the @itcl syntax directly. For example, it is a bad idea to write code like this: set {@itcl ::fred x} 3 puts "value = ${@itcl ::fred x}" Instead, you should always use the scope command to generate the variable name dynamically. Then, you can pass that name to a widget or to any other bit of code in your program. KEYWORDS
code, namespace, variable itcl scope(n)
All times are GMT -4. The time now is 02:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy