Using := in a procedure

Using := in a procedure

Post by Ken Pizzi » Sat, 13 Feb 1999 04:00:00




>Is it possible to use := to conditionally assign a default value to a variable
>whose NAME is passed to a procedure? For example:

>#!/bin/sh

>PROC()
>{
>  #This procedure is wrong, but illustrates what I'm trying to do
>  NAME=$1
>  echo Setting default for $NAME
>  ${$NAME:=/etc/hosts}
>  echo Current value of $NAME is $`eval echo $1`
>}

>PROC FILENAME1
>PROC FILENAME2
>PROC FILENAME3

Is this what you're looking for?
  PROC()
  {
    NAME="${1:-/etc/hosts}"
    echo Current value of NAME is $NAME
  }

                --Ken Pizzini

 
 
 

Using := in a procedure

Post by Sharo » Fri, 19 Feb 1999 04:00:00



> Is this what you're looking for?
>   PROC()
>   {
>     NAME="${1:-/etc/hosts}"
>     echo Current value of NAME is $NAME
>   }

>                 --Ken Pizzini

I don't think so. Actually, I think he's asking a basic question which I don't know
the answer to :

If you have, say in ksh :

a="b"

Then, is it possible to assign a value to a *variable* called b using the fact that
the string "b" is the value of the variable a ?

Something like (the following didn't work for me):

$a=c

To this I get the message:

ksh: b=c:   not found

Sharon.

 
 
 

Using := in a procedure

Post by Christopher A. Jone » Fri, 19 Feb 1999 04:00:00



> I don't think so. Actually, I think he's asking a basic question which I don't know
> the answer to :

> If you have, say in ksh :

> a="b"

> Then, is it possible to assign a value to a *variable* called b using the fact that
> the string "b" is the value of the variable a ?

> Something like (the following didn't work for me):

> $a=c

> To this I get the message:

> ksh: b=c:   not found

a="b"

eval $a="c"

echo $b
c

Regards,
Chris

http://www.perpendicularuniverse.com

- Show quoted text -

Quote:> Sharon.

 
 
 

Using := in a procedure

Post by Christopher J. Matter » Fri, 19 Feb 1999 04:00:00



> I don't think so. Actually, I think he's asking a basic question which I don't know
> the answer to :
> If you have, say in ksh :
> a="b"
> Then, is it possible to assign a value to a *variable* called b using the fact that
> the string "b" is the value of the variable a ?
> Something like (the following didn't work for me):
> $a=c
> To this I get the message:
> ksh: b=c:   not found

Something like this, perhaps (done in ksh)

$ a=b
$ echo $a
b
$ eval $a=c
$ echo $b
c

                           Chris Mattern

 
 
 

Using := in a procedure

Post by bmar.. » Sat, 20 Feb 1999 04:00:00



   >I don't think so. Actually, I think he's asking a basic question
   >which I don't know the answer to :
   >If you have, say in ksh :
   >a="b"
   >Then, is it possible to assign a value to a *variable* called b
   >using the fact that the string "b" is the value of the variable a ?
   >Something like (the following didn't work for me):
   >$a=c
   >To this I get the message:
   >ksh: b=c:   not found
eval \$a=c

Net-Tamer V 1.08X - Test Drive

 
 
 

1. Compare file modification date using tcsh built-ins

Is there any straightforward way to compare file modification dates
(i.e. which is older/newer) using tcsh built-ins?  I know ksh has the
"file1-nt" file2 and "file1-ot file2" operators for boolean expressions,
but I can't seem to find any relatively simple way of performing the
same comparision in tcsh, other than using sed/awk to extract the two
files' date fields from their "ls -l" listings and attempting to
lexographically compare two strings.

Thanks.
Ben West

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Online Linux User/Support Group

3. Stabbed US preacher flees INDIA state (The same INS tactics used against the stabbed preacher)

4. FTP HELP

5. Plug-Ins using C++

6. Can ^d be trapped?

7. How to set password using shell procedure

8. Enquiry

9. Alogorithm used by gcc to make room for local variables in procedure prologs

10. Standard procedure for multiple processes using single database?

11. Configuring RedHat wo/ using the instalation procedure.

12. In search of Solaris 2.5 Netscape Navigator 3.0 plug ins

13. Need HELP to Log User Log-ins form the internet