-
Notifications
You must be signed in to change notification settings - Fork 13
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
Shell syntax and terminology (substitution, subshells, etc.) #1
Comments
Hey sorry I've been driving cross-country for the last couple of days, but
|
Also, regarding POSIX and/or bash: I have been thinking I will probably sum
|
No worries! Have fun. |
I'm updating the grammar to name things correctly (processSubstitution and commandSubstitution) and referring to the POSIX shell specs, but they seem to contradict your point regarding subshells. I've included the relevant passages below to get your input. It's very possible I'm misreading them, or not far along enough on the journey to understand some subtlety of implementation that's going to bite me later. First, this passage in the section describing command substitution (emphasis is mine)
Further reading of the Shell Execution Environment section implies that a subshell environment is only optional in the case of a pipeline: (again, emphasis is mine)
|
This is probably an abuse of the term
...a bizarre statement, since the invocation of any external utility (simply by virtue of its being an external utility) will necessarily, always fork a subprocess... but that's not even relevant. So I don't really recommend using that link as any type of reference. But to reiterate, the condition I was referring to is when the shell has forked a child subprocess of another instance of the same shell; and I believe this is (maybe unfortunately) a rather commonly used meaning. As you've rightly pointed out, the specification also uses the term Does that make sense? |
yes, that's been my reading of it as well (and I agree about the unfortunate and confusing use of the term "subshell"). The problem of implementing these semantics are for the yet-to-be-implemented interpreter, but I definitely appreciate you taking the time to help me think through these semantics early on. Due to some the design constraints I have in mind for the interpreter, implementing subshells within the same process will probably be easier than spawning a new process anyways, so there's not much risk of ending up with the super slow approach. |
Right. I think (especially in light of the preceding confusion) that perhaps the term |
yes the new grammar (and resulting AST) makes no reference to subshells anymore, It's just "command substitution" as far as the parser is concerned. |
Regarding a JS-native shell interpreter: I've been meaning to try my hand at seeing how dash and mksh compile with emscripten for some time now actually. Since both are POSIX-compliant, decently portable, and liberally licensed, the results might be of some interest, either as starting point for writing an interpreter, or at least to compare against for accuracy. You think? In any case, I think I'll retitle this issue to be more descriptive. Would you prefer it closed, or use it for further discussion? My own opinion, issue #1 is typically as good a place as any for discussing a young project, but I don't want for impose on your 'flow', so if you'd prefer an alternate venue...? |
Couple of things:
<()
and>()
is process substitution, not command substitution.$()
and backticks are both command substitution; the first being the preferred syntax because nesting backticks is heinous. But they are 100% equivalent.I bring this up because:
[Edit: note the discussion of the use of the term
subshell
in the comments that follow.]sh -c ...
.<()
syntax is a pretty notorious bashism, although its also present in ksh93 and zsh.=()
, meaning file substitution, taking the same form as process substitution but using a regular file rather that a file descriptor or a FIFO, and can be used when data produced with<()
exceeds the pipe buffer. It is also exactly equivalent to using a tempfile.I think it might be worth asking (given the name and the tagline you've given the project), it is your intention to parse out shell or bash? I'm not super hardline anti-bash, but there are some very challenging extensions in bash (things like
[[ $* =~ (.*) ]] && BASH_REMATCH[1]
which you might be able to avoid, at least for the time being, if you were to limit yourself to POSIX shell rather than bash, per se.The text was updated successfully, but these errors were encountered: