07-11-2008
Dynamic variable values
Bit of a newbie
with regard to unix scripting and need some advice. Hopefully someone can help with the following:
I have a predefined set of variables as follows:
AAA_IP_ADD=1.1.1.1
BBB_IP_ADD=2.2.2.2
I have a funnction call which retrieves a value into $SUPPLIER which would be used as a prefix to obtain the IP address for a specific SUPPLIER. The function works and returns me a value but for explanation purposes it could be defined as follows:
$SUPPLIER=BBB
I need to now retreive the value from AAA_IP_ADD or BBB_IP_ADD based on the setting for $SUPPLIER.
So I concatenate '_IP_ADD' onto $SUPPLIER. To try and make sense of it here is what I am trying to run:
echo $SUPPLIER'_IP_ADD'
This returns a literal value and not the value stored in AAA_IP_ADD or BBB_IP_ADD
Can anyone advise how I get the actual value for these variables.
Thanks
Last edited by ronnie_uk; 07-11-2008 at 08:43 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I am stuck with extracting values by combining 2 dynamically extracted values.
The code goes like this
#!/usr/bin/ksh
ID1="abcd"
i=1 #this is a dynamic value and keeps on changing
b="ID" #this is static
now i want the value of ID1 variable.
like echo $b$i
But echo... (1 Reply)
Discussion started by: chaitanyapn
1 Replies
2. Shell Programming and Scripting
Hello,
Can somebody please give me a snippet for the below requirement.
I want to assign the values separeted by a comma to be assigned to a dynamic array.
If I give an input (read statement) like abc1,abc2,abc3,abc4,abc5, all these strings abc* should be assigned to an array like below... (2 Replies)
Discussion started by: suneelj
2 Replies
3. Shell Programming and Scripting
How do I assign values to reference variables?
I am assigning a variable name to --> $user_var
Then I am trying to change its underlying variable value by
$((user_var))=$user_value .. its failing,,
Please let me know if there is a way to do this dynamically..
FileA.props... (5 Replies)
Discussion started by: kchinnam
5 Replies
4. Shell Programming and Scripting
I found one post in another site with a solution for my problem
the below solution should explain what I want.
#!/bin/sh
first="one"
second="two"
third="three"
myvar="first"
echo ${!myvar}
But this gives error 'bad substitution'
System info
SunOS sundev2 5.9... (3 Replies)
Discussion started by: johnbach
3 Replies
5. Shell Programming and Scripting
hi
i have an input file in which there are diffrent values for xxxx,yyyyyy,zzzzzzz how can i arrange the dynamic values of x,y&z in a row.
input file:
xxxxx 1
yyyyyy 4
yyyyyy 5
zzzzzzzz 7
yyyyyy 13
zzzzzzzz 7
zzzzzzzz 6
yyyyyy 14
yyyyyy 12
zzzzzzzz 4
yyyyyy 4
yyyyyy 5
yyyyyy 6... (6 Replies)
Discussion started by: dodasajan
6 Replies
6. Shell Programming and Scripting
Hi all,
We have requirement to generate load timing based on subject areas HOUSEHOLD, BANKING and TRADING. These values are stored in an array SUB_ARR
SUB_ARR=("HOUSEHOLD" "BANKING" "TRADING")
Based on indicator files produced while processing data for each type, we need to get the stats (using... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies
7. Shell Programming and Scripting
I have a small program which needs to pass variable dynamically to form the name of a second variable whose value wil be passed on to a third variable.
***************** Program Start ******************
LOC1=/loc1
PAT1IN=/loc2
PAT2IN=/loc3
if ; then
for fpattern in `cat... (5 Replies)
Discussion started by: Cyril Jos
5 Replies
8. Shell Programming and Scripting
Hi,
I am trying to incorporate 2 functions into my `awk` command.
I want to lower case Column 2 (which is essentially the same information in Col1, except in Col1 I want to maintain the capitalization) and I want to count from 0-N that begins and ends with the start of certain markers that I... (6 Replies)
Discussion started by: owwow14
6 Replies
9. Shell Programming and Scripting
Hi Guys,
I am using a function to replace the values dynamically to frame sql query by reading a file. My file will have column names like
file.txt
col_1
col_2
expected output:
select id,col_1,col_2 from (
select a.id,
a.col_1,
rank() over (ORDER BY cast(a.col_1 AS double)... (5 Replies)
Discussion started by: Master_Mind
5 Replies
10. Shell Programming and Scripting
Hi All,
We have a requirement of picking nth position value by using cut command. value would be delimited by any symbols. We have to pass delimited value and postition to get the value in a string.
ex.
echo "A,B,C,D,E" |cut -d "," -f3
echo "A|B|C|D|E"|cut -d "|" -f2
Kindly frame the... (5 Replies)
Discussion started by: KK230689
5 Replies
LEARN ABOUT OPENSOLARIS
unset
set(1F) FMLI Commands set(1F)
NAME
set, unset - set and unset local or global environment variables
SYNOPSIS
set [-l variable [=value]] ...
set [-e variable [=value]] ...
set [-ffile variable [=value]]... ...
unset -l variable...
unset -f file variable...
DESCRIPTION
The set command sets variable in the environment, or adds variable=value to file. If variable is not equated it to a value, set expects the
value to be on stdin. The unset command removes variable. Note that the FMLI predefined, read-only variables (such as ARG1), may not be set
or unset.
Note that at least one of the above options must be used for each variable being set or unset. If you set a variable with the -ffilename
option, you must thereafter include filename in references to that variable. For example, ${(file)VARIABLE}.
FMLI inherits the UNIX environment when invoked.
OPTIONS
-l Sets or unsets the specified variable in the local environment. Variables set with -l will not be inherited by processes invoked
from FMLI.
-e Sets the specified variable in the UNIX environment. Variables set with -e will be inherited by any processes started from FMLI.
Note that these variables cannot be unset.
-ffile Sets or unsets the specified variable in the global environment. The argument file is the name, or pathname, of a file containing
lines of the form variable=value. file will be created if it does not already exist. Note that no space intervenes between -f and
file.
EXAMPLES
Example 1 A sample output of set command.
Storing a selection made in a menu:
name=Selection 2
action=`set -l SELECTION=2`close
NOTES
Variables set to be available to the UNIX environment (those set using the -e option) can only be set for the current fmli process and the
processes it calls.
When using the -f option, unless file is unique to the process, other users of FMLI on the same machine will be able to expand these vari-
ables, depending on the read/write permissions on file.
A variable set in one frame may be referenced or unset in any other frame. This includes local variables.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
env(1), sh(1), attributes(5)
SunOS 5.11 5 Jul 1990 set(1F)