Sponsored Content
Full Discussion: Variable substitution
Top Forums UNIX for Dummies Questions & Answers Variable substitution Post 302248317 by Leo_NN on Friday 17th of October 2008 09:39:52 AM
Old 10-17-2008
Variable substitution

Hi,

That might be pretty simple.
How can I generate a variable name and get their value ?

Thanks a lot.

Something like:

>CUSTOMER_NF=26
> object=CUSTOMER

> echo ${object}_NF
CUSTOMER_NF

> echo ${${object}_NF}
ksh: ${${object}_NF}: 0403-011 The specified substitution is not valid for this command.

> echo $`echo ${object}_NF`
$CUSTOMER_NF
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Substitution in a variable

Hey All, I'm trying to clean up a variable using sed but It dosn't seem to work. I'm trying to find all the spaces and replace them with "\ " (a slash and a space). For Example "Hello World" should become "Hello\ World". But it does nothing. If I put it directly into the command line it works... (3 Replies)
Discussion started by: spragueg
3 Replies

2. UNIX for Dummies Questions & Answers

variable substitution

Hi everyone, I have a simple question to ask : In a script that I'm writting, I need to create variables on-the-fly. For instance, for every iterartion of the following loop a var_X variable should be generated : #!/bin/ksh a="1 2 3" for i in $a do var_${i}=$i echo "${var_$i}" done ... (1 Reply)
Discussion started by: ck-18
1 Replies

3. Shell Programming and Scripting

Variable Substitution

I have run into a wall with my iptables firewall scripting. I am blocking all of the private side IP addresses on the WAN interface on systems running NAT. However, if the system is not running NAT and needs to allow access to the local LAN on the WAN interface, I need to block all but one of... (2 Replies)
Discussion started by: garak
2 Replies

4. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

5. Shell Programming and Scripting

variable substitution

file1.ksh #!/bin/ksh test5_create="I am a man" # test5 will be dynamic and the value will be passed from command line a=${1}_create echo $a # i need the output as "I am a man" ./file1.ksh test5 # i run the script like this any suggessions guys... (1 Reply)
Discussion started by: giri_luck
1 Replies

6. Shell Programming and Scripting

Variable Substitution

Hi , I have a variable as follows, Temp=`cat ABC.txt | cut -c5-` This will yeild a part of the date. say , 200912. I would like to substitute this variable's value in a filename. eg: File200912F.zip when i say File$TempF.zip , it is not substituting. Any help ? Thanks in... (2 Replies)
Discussion started by: mohanpadamata
2 Replies

7. Shell Programming and Scripting

How to use variable with command substitution in variable

For example I have variable like below echo $OUTPUT /some/path/`uname -n` when I try to use the variable OUTPUT like below cd $OUTPUT or cd ${OUTPUT} I am getting bad substituion error message $ cd $OUTPUT ksh: cd: bad substitution $ cd ${OUTPUT} ksh: cd: bad substitution ... (1 Reply)
Discussion started by: rajukv
1 Replies

8. Shell Programming and Scripting

Variable substitution

Hi, I have to write a shell script in which I have to substitute a variable within a variable. For example, var1=aaa var2=file.$var1.txt The output should be, echo $var2 file.aaa.txt Can someone please help me in getting this. I tried using eval, but it didnt work. I might be using it... (2 Replies)
Discussion started by: grajp002
2 Replies

9. Shell Programming and Scripting

read variable substitution

Allright so a quick question. I'm building a script that will eventually do a full IP subnet scan. It starts off by first entering an IP address, (capturing host and net ID comes after that) and I want it to use the current IP address if no input is given. Is there a quick way to define the... (1 Reply)
Discussion started by: BisMarc
1 Replies

10. Shell Programming and Scripting

Variable substitution with arrays

Hi all, I have a script with the following gist: declare -a index=(0 1 2 3 4); declare -a animals=(dog cat horse penguin cow); declare -a fruits=(orange apple grapes peach mango); declare -a drinks=(juice milk coffee tea coke); declare -a cities=(toronto paris london glasgow... (18 Replies)
Discussion started by: Kingzy
18 Replies
IS_SUBCLASS_OF(3)							 1							 IS_SUBCLASS_OF(3)

is_subclass_of - Checks if the object has this class as one of its parents

SYNOPSIS
bool is_subclass_of TRUE (mixed $object, string $class_name, [bool $allow_string]) DESCRIPTION
Checks if the given $object has the class $class_name as one of its parents. PARAMETERS
o $object - A class name or an object instance. No error is generated if the class does not exist. o $class_name - The class name o $allow_string - If this parameter set to false, string class name as $object is not allowed. This also prevents from calling autoloader if the class doesn't exist. RETURN VALUES
This function returns TRUE if the object $object, belongs to a class which is a subclass of $class_name, FALSE otherwise. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.9 | | | | | | | Added $allow_string parameter | | | | | 5.3.7 | | | | | | | Added support for $class_name to work with | | | interfaces | | | | | 5.0.3 | | | | | | | You may also specify the $object parameter as a | | | string (the name of the class) | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 is_subclass_of(3) example <?php // define a class class WidgetFactory { var $oink = 'moo'; } // define a child class class WidgetFactory_Child extends WidgetFactory { var $oink = 'oink'; } // create a new object $WF = new WidgetFactory(); $WFC = new WidgetFactory_Child(); if (is_subclass_of($WFC, 'WidgetFactory')) { echo "yes, $WFC is a subclass of WidgetFactory "; } else { echo "no, $WFC is not a subclass of WidgetFactory "; } if (is_subclass_of($WF, 'WidgetFactory')) { echo "yes, $WF is a subclass of WidgetFactory "; } else { echo "no, $WF is not a subclass of WidgetFactory "; } // usable only since PHP 5.0.3 if (is_subclass_of('WidgetFactory_Child', 'WidgetFactory')) { echo "yes, WidgetFactory_Child is a subclass of WidgetFactory "; } else { echo "no, WidgetFactory_Child is not a subclass of WidgetFactory "; } ?> The above example will output: yes, $WFC is a subclass of WidgetFactory no, $WF is not a subclass of WidgetFactory yes, WidgetFactory_Child is a subclass of WidgetFactory Example #2 is_subclass_of(3) using interface example <?php // Define the Interface interface MyInterface { public function MyFunction(); } // Define the class implementation of the interface class MyClass implements MyInterface { public function MyFunction() { return "MyClass Implements MyInterface!"; } } // Instantiate the object $my_object = new MyClass; // Works since 5.3.7 // Test using the object instance of the class if (is_subclass_of($my_object, 'MyInterface')) { echo "Yes, $my_object is a subclass of MyInterface "; } else { echo "No, $my_object is not a subclass of MyInterface "; } // Test using a string of the class name if (is_subclass_of('MyClass', 'MyInterface')) { echo "Yes, MyClass is a subclass of MyInterface "; } else { echo "No, MyClass is not a subclass of MyInterface "; } ?> The above example will output: Yes, $my_object is a subclass of MyInterface Yes, MyClass is a subclass of MyInterface NOTES
Note Using this function will use any registered autoloaders if the class is not already known. SEE ALSO
get_class(3), get_parent_class(3), is_a(3), class_parents(3). PHP Documentation Group IS_SUBCLASS_OF(3)
All times are GMT -4. The time now is 08:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy