darkphase / klish

Tool for Implementing Custom Shells

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reference/Inderect variable access in "test" and "ACTION"

GoogleCodeExporter opened this issue · comments

How can I access reference/indirect shell variables in "test" and "ACTION".
In shell script we can use reference as follows:

#!/bin/bash
x=1
REAL0=zero
REAL1=one
REAL2=two

REFER="REAL$x"

echo "REFER value ${REFER}"
echo "REAL value ${!REFER}"

test '"${!REFER}" = "$REAL1"' && echo "TRUE"

Original issue reported on code.google.com by panwar.rahul@gmail.com on 16 Oct 2013 at 5:08

Following is the example of xml, how I am trying to use it.

<VAR name="REFER"
        help="Reference variable"
        dynamic="true">
        <ACTION>
                echo -n "REAL${devid}"
        </ACTION>
</VAR>

<VAR name="REAL0"
        help="Real variable"
        dynamic="true">
        <ACTION>
                echo -n "0"
        </ACTION>
</VAR>

<VAR name="REAL1"
        help="Real variable"
        dynamic="true">
        <ACTION>
                echo -n "1"
        </ACTION>
</VAR>

<VAR name="REAL2"
        help="Real variable"
        dynamic="true">
        <ACTION>
                echo -n "2"
        </ACTION>
</VAR>

<COMMAND name="add device"
        help="add device">
        <PARAM name="devid_param"
                help="Device ID"
                value="devid"
                mode="subcommand"
                ptype="SUBCOMMAND">
                <PARAM name="devid"
                        help="Options"
                        ptype="DEVID_NUMBER_TYPE"/> <!--DEVID_NUMBER_TYPE are integers from 0 to 63-->
        </PARAM>
        <PARAM name="devtype_param"
                help="Type of device"
                value="devtype"
                mode="subcommand"
                ptype="SUBCOMMAND">
                <PARAM name="devtype"
                        test='"${!REFER}"="0"'
                        help="Options"
                        ptype="DEV_TYPE"/>
                <PARAM name="devtype"
                        test='"${!REFER}"="1"'
                        help="Options"
                        ptype="DEV_TYPE1"/>
                <PARAM name="devtype"
                        test='"${!REFER}"="2"'
                        help="Options"
                        ptype="DEV_TYPE2"/>
        </PARAM>
        <ACTION> echo "${devid} ${devtype} REFER - ${REFER} REAL - ${!REFER}" </ACTION>
</COMMAND>

Original comment by panwar.rahul@gmail.com on 16 Oct 2013 at 6:08

In above example both REFER and !REFER are giving same value REAL<num>.

Original comment by panwar.rahul@gmail.com on 16 Oct 2013 at 6:14

The klish doesn't support reference/inderect variable access.

Original comment by serj.kalichev@gmail.com on 16 Oct 2013 at 8:31

  • Changed state: Done