I have a file called /tmp/CMDB which looks like this
I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as an example, I want it to create a variable called
db_serial and populate it with value 0623AN1208
on the next iteration create a variable called
db_hostname and populate it with value server1
etc etc
so i have tried
Plus a whole load of other combinations and i just cant get the thing to work
Im sure the problem is with my use of the "eval" command which is effectively using another variable to create a variable, and assigning the value from another variable
thanks Jim, the thing is, the file /tmp/CMDB will have thousands of values. i have just given four (serial, hostname, assetid and model). The object of the script is to create a variable from the name defined to the left of the colon regardless of what it is, so my script shouldn't have any references to the "actual" variable names. e.g hostname or assetID etc.
If that file happens to have a line like this
then i want a variable created called db_bananas with a value of "woohoo" ... but it will always be the case that ill have no idea what will be in that file
The problem is not the eval expression, but the fact that pipes are executed in subshells. Therefore, variables created in while loop remain unset outside of it.
Try redirecting input without using a pipe:
Also, the $VALUE variable has a leading space in it. You should strip it off, by using
The object of the script is to create a variable from the name defined to the left of the colon regardless of what it is, so my script shouldn't have any references to the "actual" variable names. e.g hostname or assetID etc.
This should work for you.
Next time try to solve your own problems by yourself
Last edited by danmero; 06-18-2009 at 04:34 PM..
Reason: Change code
This should work for you. Next time try to solve your own problems by yourself
Thank you danmero and others, With respect to your comment above, you will see from the OP that i have indeed given clear examples of what I had tried and I have expressed that after multiple attempts at different solutions i found myself banging my head against a wall with this one.... So to say " try to solve your own problems !" I think is a little harsh
I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger.
if ]
then
echo "Only satisfied variable with value"
... (3 Replies)
hi,
I am using hp unix server and not getting variable output present inside the while loop. I have tried changing the code and need to verify whether it is proper practice of code. I am expecting the output of varible RUN_FILE 3 to TRUE which i get inside the while loop.
RUN_FILE 1=TRUE... (8 Replies)
Thanks all for taking time out and reading this thread and big Thanks to all who have come forward for rescue.
Background: I have a variable "nbrofcols" that has number of columns from a data file. Now, using this count in for loop, I am trying to get the maximum length of each column present... (7 Replies)
Hi guys,
I have a file "abc.dat" in below format:
FILE_PATH||||$F_PATH
TABLE_LIST||||a|b|c
SYST_NM||||${SRC_SYST}
Now I am trying to read the above file and want to print the value for above dollar variables F_PATH and SRC_SYST. The problem is it's reading the dollar variables as... (5 Replies)
Hi,
I am trying to do the following thing
var='date'
$var
Above command substitutes date for and in turn runs the date command and i am getting the todays date value.
I am trying to do the same thing as following, but facing some problems,
unique_host_pro="sed -e ' /#/d'... (3 Replies)
Hi all
I run my program prog.c in the following way :
$ ./prog 1 > output.txt where 1 is a user defined initial value used by the program.
But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files.
Like
$ ./prog 1... (1 Reply)
hi all,
i am experiencing an error which i think an incorrect syntax for the where clause passing a variable was given. under is my code.
sqlplus -s ${USERNAME}/${PASSWORD}@${SID} << END1 >> $LOGFILE
whenever sqlerror exit
set serveroutput on size 1000000
declare
l_rc ... (0 Replies)
I would like to know how to pass a variable inside a variable to a function.
sample code below
--------------
for x in 1 9
do
check_null $C$x ##call function to check if the value is null
if
then
echo "line number:$var_cnt,... (2 Replies)