variable population

Hello,

can someone tell me what I’m doing wrong??

:local containerName "lego"
:put [/container find comment~("" . $containerName)]                 
*4
:local containerID [/container find comment~("" . $containerName)]
:put $containerID

If I output the command I can see the container ID, but if I try to store the value on a variable it is empty..

many thx

If this is executed directly from CLI shell put whole script between {} (for saved ROS scripts and running them with /system/script/run this is not necessary) or if there are few short commands place all commands in single line separated by ;.
Issue is happening because local variables are only persisted in executed context of command by line unless are grouped in block with {} along with other commands, it doesn’t remain persisted as shell instance variable, if you are expecting it will do as in some other OS shell. It is also possible to define global variable (aka environment variable) with :global <var_name> command, such variable will remain persisted in memory and available for all CLI sessions and system scripts (in some cases not if script is executed by system user like Netwatch events) until is deleted or ROS is restarted.
Why first :put prints ID is because ~ operator is regex match against string and if string is empty (empty string concatenated with non existing variable results empty string) it will match all in ROS (guessing you have only one container created), it is more optimal to use = if you don’t need regex pattern matching.
Also no need to concatenate variable to empty string, it can be put directly into string and its value will be placed in it - comment=“$containerName” or even without “” since it is already string variable - comment=$containerName