rhai icon indicating copy to clipboard operation
rhai copied to clipboard

Escape string interpolation

Open hack3ric opened this issue 3 years ago • 1 comments

Writing Bash scripts in Rhai is somewhat uncomfortable when it comes to Bash's ${VAR} syntax:

cmake .. ${cmake_args[@]}
ninja

Currently I have to write

let script = `
  cmake .. ${"${cmake_args[@]}"}
  ninja
`;

Could there be some forms of escaping this syntax, either double dollar sign ($$) similar to writing back-ticks (``), or a more general escape pattern that includes \$ (or more broadly, \`)?

hack3ric avatar Jan 23 '23 06:01 hack3ric

The thing is, anything wrapped in backticks are supposed to be literal, meaning that there are no escapes.

True that it does make embedding ${ ... } inside back-ticks difficult...

You can use double quotes if you don't need interpolation:

let script = "cmake ${cmake_args[@]}\n\
              ninja";

But, of course, other than not having interpolation, you have to live with the ugly \n\ at the end of each line...

schungx avatar Jan 24 '23 00:01 schungx