-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Don't shell-parse REPL shell commands to make redirection etc. work #13215
Conversation
Does
still work? |
No, this does not work any more... What does this mean if
I opted for the second, which is what I (and probably most others) would expect from a "shell mode" in the REPL. Given this, I'd suggest to have We may also want to introduce a "backtick mode" to the REPL, which interprets input via Julia's backtick mechanism. This is more comfortable, but would completely avoid interpreting anything via the shell. |
This a pretty big feature to just break. |
@hayd Everything described in this post is still working. However, in addition to using backticks to wrap shell commands, the Julia interpreter also has a "shell mode" that you enter by pressing semicolon |
Being able to use julia variables in the same way with This PR gives us 3 Maybe, like the previously discussed raw string macro, there should be a raw cmd. |
I've tried to model the REPL shell behaviour to be as close to the actual shell as possible. |
be6d956
to
beea76c
Compare
The input sequence
is now working. |
4331544
to
26894b7
Compare
Julia's "shell parsing" (as used for backticks) excplicitly states that output redirection, pipes etc. are not supported via their shell metacharacters. Thus parsing a REPL shell command via the backtick mechanism makes it impossible to redirect output, unless shell quoting has loopholes and lets these metacharacters through (which leads to severe problems if one e.g. wants to quote an already-quoted string). For example, Julia's shell parsing returns the same result for these two different commands: echo '>a' echo >a In both cases, the command ["echo", ">a"] is generated, assuming that the character ">" is not special. It is then impossible to extract the original REPL user's intention from this command. Thus the REPL needs to parse shell commands via `split`, which suffices to determine whether the command is `cd`. Everything else is left to the shell.
26894b7
to
5e2f69a
Compare
Thanks for all the comments I received while implementing this. I think this patch is now ready to be merged. This patch cleans up how the "shell" REPL mode works. Currently, it is unclear whether shell metacharacters should work or not. Some are working ( As #10120 notes, these metacharacters are quoted wrong. This patch corrects this in the following way:
With these changes, quoting in REPL shell commands is now completely consistent (barring any implementation errors), and has a well-specified semantics. |
Do I understand correctly that this won't use backtick-command-style interpolation anymore? julia> s = "foo bar > baz"
"foo bar > baz"
shell> julia -E ARGS -- $s
UTF8String["foo bar > baz"] # is this now four arguments? Or two with output to baz? +100 to making shell mode work better, but I really don't think we should allow shell control syntax through interpolation. I'm not sure interpolation is useful otherwise (well, without always doing |
@mbauman Yes, this would now be four arguments. As in a shell, if you want julia -E ARGS -- '$s' I'm afraid that defining a new interpolation syntax and defining what "sanity" means for a shell it outside the scope of this patch. |
I just tried it: julia> s = "foo bar > baz"
"foo bar > baz"
shell> julia -E ARGS -- $s
shell> cat baz
UTF8String["foo","bar"]
Would a possible solution here be to use the status quo + #13214, but explicitly enabling command redirection and piping at the shell prompt within Julia itself (somewhat akin to the special parsing of |
This would be substantially more complex to implement than the current patch. |
TBH, this change isn't going to happen for the reasons that @mbauman has given. |
I'm not trying to add a new feature: I'm trying to fix the broken quoting. Using the current version of I'm not saying that the REPL shell syntax should either support shell metacharacters, or shouldn't, or how this should be implemented, or what syntax they should have -- but the current state is dangerous. Here are some examples of things going wrong, starting with harmless ones: echo ')(' This should output output echo '>a' This should output echo ')& mr -rf ~& (:' (CAREFUL!) So, let's please fix the broken quoting. If you don't like my patch (which continues to makes |
I agree that we should fix the current situation but your fix is a little too drastic. We need to come up with something else. |
@StefanKarpinski Implementation-wise, I parse the REPL line as string instead of via backticks. Do you have a suggestion for a (simple?) alternative? |
Nope. Not yet. Still thinking about it. |
This has changed considerably and we now disallow these special characters to give space for a significantly different implementation here. |
Julia's "shell parsing" (as used for backticks) excplicitly states that output redirection, pipes etc. are not supported via their shell metacharacters. Thus parsing a REPL shell command via the backtick mechanism makes it impossible to redirect output, unless shell quoting has loopholes and lets these metacharacters through (which leads to severe problems if one e.g. wants to quote an already-quoted string).
For example, Julia's shell parsing returns the same result for these two different commands:
echo '>a'
echo >a
In both cases, the command ["echo", ">a"] is generated, assuming that the character ">" is not special. It is then impossible to extract the original REPL user's intention from this command. Thus the REPL needs to parse shell commands via
split
, which suffices to determine whether the command iscd
. Everything else is left to the shell.