bash icon indicating copy to clipboard operation
bash copied to clipboard

Serializing scripts with selective escaping

Open cgohla opened this issue 3 years ago • 1 comments

I have a use case for the following kind of function (nevermind the name):

bytes' :: [Identifier] -> Statement t -> Expression t

The idea is to obtain an escaped string literal (or some Concatenation of Literals and ReadVarSafes) representing the statement, but where the given identifiers are not escaped. I want to be be able to pass the resulting statement to eval while capturing the values referred to by the listed identifiers.

As an example, I want to be able to produce a script like this:

  baz=boom
  eval "foo=bar ; echo $baz\$foo"

which should output boombar.

I'm definitely going to try to implement this, but I haven't thought about the details.

Thoughts?

Alternative

One could use the existing bytes and apply some string replacement to remove the unwanted escapes, but this might get tricky when there are several levels of escapes involved.

cgohla avatar Feb 19 '22 23:02 cgohla

I've thought better of it, and it seems I won't need this feature, so feel free to close.

cgohla avatar Mar 26 '22 15:03 cgohla