Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlines in --prepend #5

Open
mverleg opened this issue Oct 26, 2019 · 1 comment
Open

Newlines in --prepend #5

mverleg opened this issue Oct 26, 2019 · 1 comment

Comments

@mverleg
Copy link

mverleg commented Oct 26, 2019

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.
@stevedonovan
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants