Sponsored Content
Top Forums UNIX for Advanced & Expert Users Compound indirect variable references Post 81325 by tkrussel on Thursday 18th of August 2005 10:26:50 AM
Old 08-18-2005
Compound indirect variable references

Using bash, I'm trying to read a .properties file (name=value pairs), assigning an indirect variable reference for each line in the file.

The trick is that a property's value string may contain the name of a property that occurred earlier in the file, and I want the name of the 1st property to be replaced with the value of that property.

Here's what I have so far:

###############sample.properties:###############
basePath=/home/joe
fullPath=${basePath}/data
###############End sample.properties###############

###############PropertyReader.sh###############
#! /bin/bash
declare -a settings
settings=(`cat sample.properties | tr '\n' ' '`)
for setting in "${settings[@]}"; do
echo
echo "line:"
echo ${setting}

declare -a settingString
settingString=(`echo -n ${setting/=/ }`)
eval "${settingString[0]}="'"$settingString[1]"'

echo "result:"
eval 'echo "${settingString[0]}='"${settingString[1]}"'"'
done
###############End PropertyReader.sh###############

###############output###############

line:
basePath=/home/joe
result:
basePath=/home/joe

line:
fullPath=${basePath}/data
result:
fullPath=basePath[1]/data
###############End output###############
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to use 'compound variable' in a script

Hi there - am newish to shell scripting and would appreciate some advice on this... Am trying to use what I have seen called 'compound variables' in other langs but with no success in my shell script. This is the kind of thing I'm trying to do: base_val=123 stop=3 x=1 while do ... (3 Replies)
Discussion started by: neemic
3 Replies

2. Shell Programming and Scripting

Trying to use 'compound variable' in a script

Erase the space in assigment operator. array_var=`expr $base_val + $x` (1 Reply)
Discussion started by: irina
1 Replies

3. Shell Programming and Scripting

Length of an indirect variable

The construct ${#parameter} returns the number of characters in the parameter and ${!parameter} specifies an indirect variable. My question is: How do I combine these two. What I want is ${#!parameter} but this gives an error. Of course I can use: dummy=${!parameter} ${#dummy} but that's a... (0 Replies)
Discussion started by: gone_bush
0 Replies

4. Shell Programming and Scripting

compound variable in korn shell

in a text " Korn Shell Unix programming Manual 3° Edition" i have found this sintax to declare a compoud variable: variable=( fild1 (0 Replies)
Discussion started by: ZINGARO
0 Replies

5. Shell Programming and Scripting

compound variable in korn shell

in a text " Korn Shell Unix programming Manual 3° Edition" i have found this sintax to declare a compoud variable: variable=( fild1 fild1 ) but this sintax in ksh and sh (HP-UNIX) not work... why?? exist another solution for this type of variable ??? (5 Replies)
Discussion started by: ZINGARO
5 Replies

6. Linux

How to get an Indirect Variable Value..?

Hi, I've got a small problem. If varible A stores "B" and Variable B stores C, How to get the value of variable B by using only Variable A..? I tried the following but didnt work pease help.. $ var1=vikram $ echo $var1 vikram $ vikram=sampath $ echo $vikram sampath $ echo... (6 Replies)
Discussion started by: vickramshetty
6 Replies

7. Shell Programming and Scripting

Indirect variable assignment

Hi I have variable A_B=alpha also var1="A" var2="B" I want to retrieve the value alpha using var1 and var2 , somthing like echo ${${var1}_${var2}} that works. Obviously this is receiving syntax error (6 Replies)
Discussion started by: sumir
6 Replies

8. Shell Programming and Scripting

Refering to compound variables with a variable name

Hello, Here is my problem using KSH I have a set of compound variables, let say cmp_var1 cmp_var2 The names of these variables are stored in an indexed array. How can I access the subfields of these compound variables ? I tried: set -A cmp_varnames=(cmp_var1 cmp_var2) for cmp in... (4 Replies)
Discussion started by: luky55
4 Replies

9. Shell Programming and Scripting

Indirect variables in Bash

Hello, I've spent hours this morning reading various past forum posts and documentation pages but I can't find exactly what I need. I'm trying to call a variable with a variable in the name without having to make a third variable. For example: path=AB legAB=50 leg$path I want to... (8 Replies)
Discussion started by: DFr0st
8 Replies
svcprop(1)                                                                                                                              svcprop(1)

NAME
svcprop - retrieve service configuration properties SYNOPSIS
svcprop [-fqtv] [-C | -c | -s snapshot] [-p [name/]name]... [FMRI | pattern]... svcprop -w [-fqtv] [-p [name/]name] {FMRI | pattern} The svcprop utility prints values of properties in the service configuration repository. Properties are selected by -p options and FMRI op- erands. By default, when a single property is selected, its values are printed separated by spaces on a single line. Empty ASCII string values are represented by a pair of double quotes (""). Bourne shell metacharacters (';', '&', '(', ')', '|', '^', '<', '>', newline, space, tab, backslash, '"', single-quote, '`') in ASCII string values are quoted by backslashes (). When multiple properties are selected, a single line is printed for each. Each line comprises a property designator, a property type, and the values (as described above), separated by spaces. By default, if a single FMRI operand has been supplied, the property designator con- sists of the property group name and the property name joined by a slash (/). If multiple FMRI operands are supplied, the designator is the canonical FMRI for the property. A composed property may be selected directly from the entities which match a specified FMRI or from entities which may be used as a source of properties for these matching entities. An example of a composed property is a property which is set on a service, which may be selected when an instance matching an FMRI does not possess the property itself. An un-composed property selection is made against the specified FMRI with no further searching of additional sources of properties other than the entities which match the designated FMRI. Properties are displayed either with or without composition depending on the options which are supplied at invocation. Properties are com- posed by default. A snapshot, which is a point in time representation of the state of a matching entity's properties at a moment in time, always uses compo- sition because snapshots are always composed. Error messages are printed to the standard error stream. Many properties have specific meanings to the Service Management Facility or the service's restarter. The following options are supported: -C Retrieves the current property values, without composition. -c Retrieves the current property values, with composition. -f Designates properties by their FMRIs. Implies option -t. -p [name/]name Prints values of the named property or property group for each of the property groups, instances, or services spec- ified by the operands. -q Quiet. Produces no output. -s snapshot Uses the named snapshot to retrieve the specified property or property group, with composition (since snapshots are always composed). If the given property group is not present in the snapshot, the current property values are exam- ined. -t Uses the multi-property output format. -v Verbose. Prints error messages for nonexistent properties, even if option -q is also used. -w Waits for the selected property group or property to change before printing anything. This option is only valid when a single entity is given. If more than one operand is given, or an operand matches more than one instance, an error message is printed and no action is taken. The -w option always causes svcprop to operate against current property values. The following operand is supported: FMRI With no -p options, FMRI operands can name a service, instance, property group, or property. For services, service instances, and property groups, all contained properties are selected. Instances and services can be abbreviated by specifying the instance name, or the trailing portion of the service name. Properties and property groups must be specified by a full FMRI. For example, given the FMRI: svc:/network/smtp:sendmail The following are valid abbreviations: sendmail :sendmail smtp smtp:sendmail network/smtp The following are invalid abbreviations: mail network network/smt Abbreviated forms of FMRIs are unstable and should not be used in scripts or other permanent tools. Arguments to the -p option can name property groups or properties. In the former case, operands can name services or instances, and all properties in the named property group of the named services or instances are printed. In the latter, operands can name services, instances, or property groups, and the named properties belonging to the operands are printed. By default, all properties are selected from the running snapshot, with composition. If there is no running snapshot, then current properties are selected. The -w and -s options can be used to change the source of properties. When walking properties, that is, no -p options, current nonpersistent property groups are also selected. With -p options, if the property group doesn't exist in the running snapshot, then if the property group is nonpersistent the current property or property group is selected. Example 1: Displaying the Value of a Single Property The following example displays the value of the enabled property in the general property group of instance default of service inetd. example% svcprop -p general/enabled network/inetd:default true Example 2: Displaying All Properties in a Property Group This example displays all properties in the general property group of service ntp. example% svcprop -p general ntp general/entity_stability astring Unstable general/single_instance boolean true Example 3: Verifying the Existance of a Property This example verifies the existence of the general/enabled property for all instances of service identity. example% svcprop -q -p general/enabled identity: example% echo $? 0 Example 4: Waiting for Property Change This example waits for the sendmail instance to change state. example% svcprop -w -p restarter/state sendmail Example 5: Using svcprop in a Script example% cat getval #!/bin/sh svcprop -p $1 $2 | ( read value v2 if [ -n "$v2" ]; then echo "Multiple values!"; exit; fi echo $value ) The following exit values are returned: 0 Successful completion. 1 An error occurred. 2 Invalid command line options were specified. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ svcs(1), inetd(1M), svcadm(1M), svccfg(1M), svc.startd(1M), service_bundle(4), attributes(5), smf(5), smf_method(5), smf_security(5) 18 Mar 2005 svcprop(1)
All times are GMT -4. The time now is 09:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy