Wildfly/JBoss CLI: How can I set a variable to the result of an expression?

1.1k Views Asked by At

I have an expression that reads the user-name attribute of a datasource:

[standalone@localhost:9990 /] /subsystem=datasources/xa-data-source=MYDATASOURCE:read-attribute(name=user-name)
{
    "outcome" => "success",
    "result" => "DS_USERNAME"
}

I would like to store that result in a variable, so that I can use it in other expressions.

If I simply use set, it will set the variable as the expression itself, rather than the result:

[standalone@localhost:9990 /] set DSUSER=/subsystem=datasources/xa-data-source=MYDATASOURCE:read-attribute(name=user-name)
[standalone@localhost:9990 /] echo $DSUSER
/subsystem=datasources/xa-data-source=MYDATASOURCE:read-attribute(name=user-name)

[standalone@localhost:9990 /] $DSUSER
{
    "outcome" => "success",
    "result" => "DS_USERNAME"
}

I really just want to set DSUSER somehow, such that 'echo $DSUSER' results in 'DS_USERNAME':

[standalone@localhost:9990 /] echo $DSUSER
DS_USERNAME

Is there any way I could do that? (I've tried piping it to grep, but this grep doesn't support regex capture groups)

1

There are 1 best solutions below

0
On

I believe you can do it using backticks (`) like:

set DSUSER=`/subsystem=datasources/xa-data-source=MYDATASOURCE:read-attribute(name=user-name)`