Simple shell variable expansion failing in REMOTE::SSH command

Simple shell variable expansion failing in REMOTE::SSH command
0

#1

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.


No writeDebug() output with command-runner full-command --verbose
#2

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


#3

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

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

#4

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


#5

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.


#6

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


#7

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


#8

Thank you! This documentation is great.