Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

shell scripts problem

Look at this script

set +x
y=SUCCESS
x=y
z=x
echo $`echo $z`
echo "$g"
#exec $g

I am trying to print the value in variable 'y' without using variable 'y'.
In this example i want to print "SUCCESS" without using variable 'y'.

My requirements are like this, can't help this. Actually i am storing a string in variable 'y' which is name of a script i want to execute.

solutions will be greatly apprecaited.

Thanks
GG

0
ilikenine
Asked:
ilikenine
  • 2
  • 2
  • 2
  • +3
1 Solution
 
jlevieCommented:
I'm having a bit of a problem understand what you are trying to accomplish. From the first part of your requirement you could do:

x=y
echo $x

which will print what y contains without directly using y.

But it seem from the way the question is phrased that that isn't quite what you want. Could you elaborate, please?
0
 
ahoffmannCommented:
eval echo \$$x
0
 
griesshCommented:
Are you doing something like this:

y='ls -l'
z=y
eval $"$z"

======
Werner
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
UkWizardCommented:
Wow, that really does not make sense, what exactly are you trying to do ?
0
 
griesshCommented:
UKWizard

Either ilikenine is just playing ( then (s)he wouldn't offer 200 points ) or there IS a reason behind the problem even if it doesn't make sense to us.

=====
Werner
0
 
yuzhCommented:
I don't understand what you try to do, may be the following
is the answer for your question:

   set +x
   y=SUCCESS
   x=$y          
   z=$x
   then you can use x and z without directly using y.


0
 
jlevieCommented:
Yeah, I think that there's a real question here, but the way it's stated doesn't adaquately describe the problem. Hopefully yhe questioner will come back and give us a better descript of the problem.
0
 
ilikenineAuthor Commented:
Sorry, agree that i haven't mentioned the problem very clearly.
For the points part, i am new to this place and am not sure how points thing work, don't have the enthu to read either, so i will surely give those points i said. But next time i will be careful that i don't give away points so easily (^_^)

Well my prob:
I have a pram file param.sh
contents :
export JOB1="job1.sh abcd"

export JOB1_STAT=P

Now i have a restart file
contents
JOB1_STAT=R

Now i have my main script, prog.sh
contents:
. param.sh
env | grep -i "JOB" | grep -v "_STAT" | awk '{FS="="} {print $1} | read STEP

Now variable STEP will have the value JOB1
I have to do it like this
. ${$STEP}

Now i tried what griessh said.
I said
eval $"$STEP"
and it is cool... thanks griessh...

Hope this time i am able to mention it clearly.
Thanks
0
 
ilikenineAuthor Commented:
Thanks Griessh for that
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now