runner
runner copied to clipboard
Newlines in --prepend
I'm having a bit of trouble with --prepend
:
echo -e 'let a = 3;\nprintln!("{}", a + 2);' > mwe.rs
If I run
runner --prepend "// pre\n" mwe.rs
then I get an error. I think that's because there is no newline after the prefix, which means the first line gets swallowed by a comment. It seems Bash likes swallowing trailing whitespace.
24 | println!("{}", a + 2);
| ^ not found in this scope
Maybe either or both of these solutions could be applied:
- Put a newline after the prepended text by default (easy and avoids mistakes, but doesn't allow newlines in the prepend text).
- Replace any "\n" by a real newline. Convenient for adding any newline anywhere despite shell escaping.
I've used Bash for twenty years and still think it's a bastard. In my current work I've been converting the string "\n" into the char '\n' but, again, there's going to be surprises with actual quoted strings with the second approach. It's probably the best, with documented limitations. I like the first as well, since not wanting that linefeed would be pretty rare!