Simple shell variable expansion failing in REMOTE::SSH command

In command-runner full-command mode, this:

#! REMOTE::SSH
foo="some bar"; echo "${foo}foobar"

fails with:

Description = No such variable 'foo' in 'foo="some bar"; echo "${foo}foobar"',

This sort of thing becomes essential if you want to do something like split a string. E.g.,

split_me="foo,bar"; IFS=',' read -ra arr <<< "${split_me}"; echo "${arr[0]}"

should echo “foo”

Let me know if you want more info to reproduce this.

command-runner version: 6.0.62

This one is really causing me a lot of headaches on a high priority bug fix right now :frowning:
(https://indeni.atlassian.net/browse/IKP-1800)

I created and IKP bug to track this issue. It has a lot more information, including exact steps to repro and a test.ind script:

https://indeni.atlassian.net/browse/IKP-1975

It’s possible to escape it with an additional $; for example:

#! REMOTE::SSH
foo="some bar"; echo "$${foo}foobar"
1 Like

Thanks Eyal, that’s helpful. Can you explain why the standard syntax doesn’t work? Any way to fix?

It’s not that the standard syntax doesn’t work, but rather it’s because we have the tag / dynamic variable injection mechanism. ${foo} is an ind script feature which allows one to inject a tag / dynamic variable to the remote operation and this is how the commands interprets this syntax. In order to tell the command to ignore this interpretation and use the expression as is, one has to escape it - the way to do it is by using an additional $ character. This is much like any escape character in any other language; for instance ,\ in regular expressions.

Ahh, that makes sense. Thanks for explaining, Eyal: I should have thought of the tag / dynamic var syntax.

Well, this one definitely threw me for a loop. Given that, I want to at least suggest that using some syntax other than ${var} to represent custom indeni tags/dynamics seems worth considering. I’m sure you’ve thought about this already, so I’m really not trying to be snarky here. And, I doubt I’ll be the last person who’s very confused by this.

I’ll do my best to document this in the wiki.

I’ll close: https://indeni.atlassian.net/browse/IKP-1975

documented here: https://indeni.atlassian.net/wiki/spaces/IKP/pages/560103453/Remote+SSH+Shell+Commands+and+IND+Dynamic+Vars

1 Like

Thank you! This documentation is great.

1 Like