value of a value question...

value of a value question...

Post by David Stabl » Tue, 14 May 1996 04:00:00





Quote:>I want to be able to get $(value_of_result) so that it is
>equal to $1 or more exactly I want to get to the value of $1 where the
>value of result=1 by $(value_of_result)...

Sounds like you need

A=`eval echo \$$RESULT`

where the first pass results in a $ followed by the value of RESULT,
which is then turned over to echo, and set into the variable A when
command substitution occurs.

The problem is, \$$ returns the current PID.

Can someone refine this so that it works?

-d.

 
 
 

value of a value question...

Post by Raymond Canfiel » Tue, 14 May 1996 04:00:00


Ok, here is a question for ya...
If I am running a sh script and I do a set `ls ~/txt/` and I am also
setting select as a number between 1 and the number of files in ~/txt/
as "result", I want to be able to get $(value_of_result) so that it is
equal to $1 or more exactly I want to get to the value of $1 where the
value of result=1 by $(value_of_result)...

thanks...
--
-rwc

  System Installation / Maintenance - Digital Express Group, Inc.

 
 
 

value of a value question...

Post by Andreas Schw » Thu, 16 May 1996 04:00:00




|>> I want to be able to get $(value_of_result) so that it is
|>> equal to $1 or more exactly I want to get to the value of $1 where the
|>> value of result=1 by $(value_of_result)...

|> Sounds like you need

|> A=`eval echo \$$RESULT`

|> where the first pass results in a $ followed by the value of RESULT,
|> which is then turned over to echo, and set into the variable A when
|> command substitution occurs.

|> The problem is, \$$ returns the current PID.

|> Can someone refine this so that it works?

Use this, which also saves a process:

  eval value_of_result=\$$result
--
Andreas Schwab                                      "And now for something

 
 
 

value of a value question...

Post by Parris Geis » Thu, 23 May 1996 04:00:00


Of course there is always another way ...
        eval print '$'$name

                parris





> |>> I want to be able to get $(value_of_result) so that it is
> |>> equal to $1 or more exactly I want to get to the value of $1 where the
> |>> value of result=1 by $(value_of_result)...
> |> Sounds like you need
> |> A=`eval echo \$$RESULT`
> |> where the first pass results in a $ followed by the value of RESULT,
> |> which is then turned over to echo, and set into the variable A when
> |> command substitution occurs.
> |> The problem is, \$$ returns the current PID.
> |> Can someone refine this so that it works?
> Use this, which also saves a process:
>   eval value_of_result=\$$result
> --
> Andreas Schwab                                      "And now for something


 
 
 

1. Better Way to Get Value of Value of Variable in Bourne shell?

Hi

I need to create a Bourne shell function that can change/manipulate the values
of the given variable names, e.g.

  $ P1=John
  $ P2=Jane
  $ P3=Paul

  $ echo "1=$P1, 2=$P2, 3=$P3."
  1=John, 2=Jane, 3=Paul.

  $ add_prefix Hi_ P1 P2 P3

  $ echo "1=$P1, 2=$P2, 3=$P3."
  1=Hi_John, 2=Hi_Jane, 3=Hi_Paul.

After several trial-and-error, I finally got the add_prefix() working, but I
think my solution is too complicated and inefficient, specifically the
"eval $var='$prefix`eval echo \\$$var`'" that takes 2 evals and 1 command
substitution, as shown below.

  add_prefix () {
    prefix=$1
    shift
    for var in $*; do
      eval $var='$prefix`eval echo \\$$var`'
    done
  }

Can any Bourne shell programming guru show me a more concise, efficient and
elegant way in writing the add_prefix() function without using any external
command?

Is there any shorter syntax like ${$var} in Bourne shell that can replace
`eval echo \\$$var` ?  Something concise and simpler will be helpful because
the actual function I need to write is much more complicated than add_prefix()
function shown above.

Thanks.  I appreciate your help.

Regards
Hon-Chi

2. DHCP client DNS problem.

3. obtaining the value of a value of a variable?

4. NLSPATH Problems under Solaris 2.5

5. How to enter values during pkgadd installation and pass those values to postinstall process?

6. USB-IEEE 1284 converter as Digital IO

7. Find numeric value in xml file, recalculate, and replace old value

8. SOCKS'ified xmcd binaries - where?

9. settimeofday(2) succeeds for microsecond value more than USEC_PER_SEC and for negative value

10. Stripping out value from file, value is a variable though.

11. Echoing value of variable when value contains "$"

12. ksh: finding the value of a value in a for loop