I am trying to use eval command to evaluate a variable(HAPROXY_LISTENER_rabbitmq_project-test-BRHM_PORT) which consists of '-' but unfortunately the eval command is unable to interpret the value of variable and trims the variable name after '-' and produces the string output rather than the actual value of the variable.Is it kind a restriction in eval command?What other options do we have?
Last edited by Scrutinizer; 12-04-2013 at 02:44 PM..
Reason: code tags
- is not a valid character for a variable name. If you include it by forcing it via ${variable-name}, it will take that to mean "default to the value of 'name' when 'variable' is undefined".
There are probably much, much, much better ways to accomplish your goal than 80-character variable names and mucking with eval. Can you please tell me your actual goal? And I don't mean "dynamic variable names", I mean the actual problem you are trying to solve.
The hyphen can be used in CoBOL code, but it is considered as plain text for Unix shells. I've fallen across this the other way around when I wanted to set a variable to a value built from another variable like this:-
I wanted to end up with myfile_20131206 as the filename format and I got very confused because it always evaluated to just 20131206 (or whatever the date was)
This was because the underscore is considered part of the variable name and the variable fileheader_ was undefined. This is not pretty, but I had to change the code to read:-
.... and learn from my error.
I too would like to know what you are actually trying to achieve. We might have a better way to do it, save you some hassle and provide something for others to read and learn from. Indeed, I'm quite happy to learn myself if there is a better way than I am currently using.
Hi Robin/Corona688,
In your example its an underscore which works well but in my case the dynamic variable has a value which consist of a dash(-)
Actually am using eval to evaluate dynamic variables and one of the variable has the value with "-"(Dash).
Lets take the following example:
where HAPROXY_LISTENER_NAME is a variable with value "search-engine" so the above variable HAPROXY_LISTENER_PORT should evaluate to this:
But actually it evaluates to this:
Any suggestion would be deeply appreciated.
Moderator's Comments:
edit by bakunin: please use CODE-tags yourself. Thank you.
Hi All,
I read the above written code (perl code) in another perl script and evaluates this code for each line of text file,but using exit statement in code make this not to work and i could not get the desired results. However if i use return it works fine. I just need to know why it doesn't... (1 Reply)
Hi all,
some small script with eval turned me to crazy.
my OS is linux
Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux
below script works well
#!/bin/bash
eval ssh remotehost date
eval ssh remotehost ls
below... (1 Reply)
I have file called myfile which has the text "myserver" in it. I need to have a command to ping "myserver". How would I do that?
I tried
when I type at the terminal I get the output as . How do I do something like a ?
thanks,
Nick (5 Replies)
Hi all,
Can you please tell me the command, with which one can know the amount of space a specific directory has used.
df -k . ---> Displays, the amount of space allocated, and used for a directory.
du -k <dir name> - gives me the memory used of all the files inside <dir>
But i... (2 Replies)
Hi Gurus,
I am having 2 parameters as below
parm1=value1
parm2=parm1
I want to evaluate parm1 value using eval echo \$$parm2 and later i want to assign this value to other variable which i will be using in if statement like :
if ]; then
do this.......
fi
could you please suggest... (5 Replies)
Help !!
First, Thanks in Advance
Here is what I have
I have an environment Variable, let's call it v_VALUE.
v_VALUE="\$ORACLE_HOME/bin" Hence, the location is ORACLE_HOME is not evaluated. ORACLE_HOME happens to be /app/oracle/product/10.1.2
I need a method of returning the... (1 Reply)
how can I find cpu usage memory usage swap usage and
I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times
my final destination is monitor process
logical volume usage above X % and number of Logical voluage above
can I not to... (3 Replies)
Hi
i have the following code:
if(($line!=1) and (@field!='\$')){
print ( "\nTRY TO CONNECT TO DATABASE................\n");
my $dbh = DBI->connect($dsn, $user, $pass);
print ("CONNECTED TO DATABASE\n");
eval
... (1 Reply)