Open
Description
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.]
- Command substitution does not necessarily invoke a subshell, and in most cases won't. The only thing it guarantees is out-of-order evaluation: it simply evaluates the expressions inside the substitution first, then evaluates the surrounding statement using the results of the substitution.
- There aren't any builtins that explicitly mean 'subshell'; to do exactly that (without a compound action or backgrounding the task), its just
sh -c ...
. - Process substitution always invokes a subshell, since it is equivalent to invoking the expression inside the substitution and redirecting its output to an anonymous file descriptor in a background task, then invoking the outer expression with its input being the contents of that file descriptor. The
<()
syntax is a pretty notorious bashism, although its also present in ksh93 and zsh.- zsh (...and very recent bash?) also has the related
=()
, 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.
- zsh (...and very recent bash?) also has the related
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.
Metadata
Metadata
Assignees
Labels
No labels