Bernd Eggink <bernd.eggink@xxxxxxxxxx> wrote:
I noticed that, while this works:
slsh> s = "print(\"foo\")"; eval(s);
"foo"
this doesn't:
slsh> s = "print(\"foo\nbar\")"; eval(s);
***string***:1: Expecting a quote-character: found '??'
It seems that eval() doesn't like statements with a line break in it,
but I found no such limitation mentioned in the docs.
Here is what the eval function saw:
print("foo
bar")
This is not a valid statement since the parsing of the string "foo..."
stopped at the newline. You need to pass to the eval function one of
the string forms such as:
print("foo\nbar");
print(`foo
bar`);
print("foo\n\
bar");
The above 3 forms would be coded as:
s = "print(\"foo\\nbar\")"; eval(s);
s = "print(`foo\nbar`)"; eval(s);
s = "print(\"foo\\n\\\nbar\")"; eval(s);
Note that the print function will not output a physical newline
character to the terminal. If you want that, then either use the
message function, e.g.,
s = "message(\"foo\\nbar\")"; eval(s);