06-26-2012
You need to use eval to access dynamically generated variable names. And, as a further hint, with eval you'll need to quote the first $. Since eval can execute arbitrary code, use it with caution. This particular use should be fine. Read your shell man page for the details.
Your shell may provide a better alternative. Perhaps arrays. Or references. If you want help with the bigger picture, tell us which shell and os you're using and what you're trying to accomplish.
Regards,
Alister
Last edited by alister; 06-26-2012 at 09:44 AM..
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I have the following string stored in a variable from a file
sbCvgXfsuupllsucpp11-aWa
I want to use sed to search for the string in a second file: FileSys.dat
sed -n "${obid}" FileSys.dat
I'm getting "sed: command garbled: sbCvgXfsuupllsucpp11-aWa"
The syntax seems fine...anyone... (2 Replies)
Discussion started by: orahi001
2 Replies
2. Shell Programming and Scripting
Hi
I have a file in which there is list of files.
eg:
$path1/file1
$path1/file2
$path2/file3
I am trying to read this file in other script.However the value of variable i.e. $path1 and $path2 is not replaced by its value.
How to do it ?
I am trying:
while read line
do
echo... (2 Replies)
Discussion started by: dashing201
2 Replies
3. Shell Programming and Scripting
Hi everybody,
I am trying to do the thing you see in the title, and I can't simply do
a=$(svn up)
echo $a
because the program (svn) gives output on lots of lines and in the variable the output is stored on only one line (resulting in a horribly formatted text). Any tips?
Thanks,... (2 Replies)
Discussion started by: ocirne94
2 Replies
4. Shell Programming and Scripting
Hi everyone,
Ok here's the scenario.
I have a control file like this.
component1,file1,file2,file3,file4,file5
component2,file1,file2,file3,file4,file5I want to do a while loop here to read all files for each component.
file_count=2
while ]
do
file_name=`cat list.txt | grep... (2 Replies)
Discussion started by: The Gamemaster
2 Replies
5. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
couldn't print out stored variable in awk
2. Relevant commands, code, scripts, algorithms:
i have in a... (5 Replies)
Discussion started by: ymc1g11
5 Replies
6. Shell Programming and Scripting
Simple enough problem I think, I just can't seem to get it right.
The below doesn't work as intended, it's just a function defined in a much larger script:
CheckValues() {
for field in \
Group_ID \
Group_Title \
Rule_ID \
Rule_Severity \
... (2 Replies)
Discussion started by: Vryali
2 Replies
7. UNIX for Dummies Questions & Answers
Hello guys,
This truly is a newbie question. I'm trying to make a loop to execute simultaneous commands indefinitely while using variable. Here is how my mess looks like (this is just an example):
#!/bin/bash
IP=`shuf -n 1 IP.txt` # I figured this would be easier to select random lines... (4 Replies)
Discussion started by: bobylapointe
4 Replies
8. Shell Programming and Scripting
Hello All,
Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....?
I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping
through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies
9. Shell Programming and Scripting
Hi All,
I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies
10. Shell Programming and Scripting
Hi folks,
A really dumb question as I've wasted far too long trying to get this to work.... (on RH bash)
I have an array:
m0='<hello>'
m0='<there>'
m0='<fred>'
v0='<goodbye>'
v0='<again>'
v0='<john>'
in my code I calculate the value of the variable to output and if I echo it, I... (2 Replies)
Discussion started by: say170
2 Replies