Misunderstanding the purpose of a process substitution
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS)
would execute COMMANDS
and then feed the result of the program into whatever command it's a part of, so command1 <(command2)
would evaluate command2
and pass the result as the first argument into command1
.
I thought the following would've worked:
$ for i in <(cat list.txt); do echo $i; done
where list.txt
is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63
, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?
I thought the above would've worked, because it works fine when I write
$ for i in `cat list.txt`; do echo $i; done
I've never seen this `
notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?
process-substitution
add a comment |Â
up vote
1
down vote
favorite
I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS)
would execute COMMANDS
and then feed the result of the program into whatever command it's a part of, so command1 <(command2)
would evaluate command2
and pass the result as the first argument into command1
.
I thought the following would've worked:
$ for i in <(cat list.txt); do echo $i; done
where list.txt
is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63
, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?
I thought the above would've worked, because it works fine when I write
$ for i in `cat list.txt`; do echo $i; done
I've never seen this `
notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?
process-substitution
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS)
would execute COMMANDS
and then feed the result of the program into whatever command it's a part of, so command1 <(command2)
would evaluate command2
and pass the result as the first argument into command1
.
I thought the following would've worked:
$ for i in <(cat list.txt); do echo $i; done
where list.txt
is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63
, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?
I thought the above would've worked, because it works fine when I write
$ for i in `cat list.txt`; do echo $i; done
I've never seen this `
notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?
process-substitution
I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS)
would execute COMMANDS
and then feed the result of the program into whatever command it's a part of, so command1 <(command2)
would evaluate command2
and pass the result as the first argument into command1
.
I thought the following would've worked:
$ for i in <(cat list.txt); do echo $i; done
where list.txt
is a file containing a list of words (separated by newlines). When I run this, it simply outputs /dev/fd/63
, which I can only assume is like a temporary pathname to the output of the subshell created in the process substitution?
I thought the above would've worked, because it works fine when I write
$ for i in `cat list.txt`; do echo $i; done
I've never seen this `
notation before, what does it mean exactly? And what understanding am I lacking about process substitutions?
process-substitution
edited Aug 20 at 22:33
Rui F Ribeiro
35k1269113
35k1269113
asked Feb 9 at 2:01
user3002473
1184
1184
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
`foo`
is command substitution, not process substitution. $(foo)
is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...)))
.
With command substitution, `foo`
/$(foo)
, the output of foo
is used as words in the command line. So for in $(echo a b c)
becomes as if you'd used for i in a b c
instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.
With process substitution, <(foo)
/>(foo)
, the stdin/stdout of the process is provided as a file, so cat <(foo)
becomes as if you'd used foo > /some/file
and cat /some/file
, and tee >(foo)
becomes as if you'd done tee /some/file
and foo < /some/file
. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
`foo`
is command substitution, not process substitution. $(foo)
is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...)))
.
With command substitution, `foo`
/$(foo)
, the output of foo
is used as words in the command line. So for in $(echo a b c)
becomes as if you'd used for i in a b c
instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.
With process substitution, <(foo)
/>(foo)
, the stdin/stdout of the process is provided as a file, so cat <(foo)
becomes as if you'd used foo > /some/file
and cat /some/file
, and tee >(foo)
becomes as if you'd done tee /some/file
and foo < /some/file
. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.
add a comment |Â
up vote
6
down vote
accepted
`foo`
is command substitution, not process substitution. $(foo)
is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...)))
.
With command substitution, `foo`
/$(foo)
, the output of foo
is used as words in the command line. So for in $(echo a b c)
becomes as if you'd used for i in a b c
instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.
With process substitution, <(foo)
/>(foo)
, the stdin/stdout of the process is provided as a file, so cat <(foo)
becomes as if you'd used foo > /some/file
and cat /some/file
, and tee >(foo)
becomes as if you'd done tee /some/file
and foo < /some/file
. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
`foo`
is command substitution, not process substitution. $(foo)
is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...)))
.
With command substitution, `foo`
/$(foo)
, the output of foo
is used as words in the command line. So for in $(echo a b c)
becomes as if you'd used for i in a b c
instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.
With process substitution, <(foo)
/>(foo)
, the stdin/stdout of the process is provided as a file, so cat <(foo)
becomes as if you'd used foo > /some/file
and cat /some/file
, and tee >(foo)
becomes as if you'd done tee /some/file
and foo < /some/file
. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.
`foo`
is command substitution, not process substitution. $(foo)
is also command substitution, and is the preferred form since it is easier to use nested command substitution: $(foo1 $(foo2 $(foo3 ...)))
.
With command substitution, `foo`
/$(foo)
, the output of foo
is used as words in the command line. So for in $(echo a b c)
becomes as if you'd used for i in a b c
instead. The command in the command substitution is executed first, its output obtained, and then the output is used to create the next command line, which is then executed, and so on. Field splitting, wildcard expansion, etc. happen, so quoting is an important consideration in command substitution.
With process substitution, <(foo)
/>(foo)
, the stdin/stdout of the process is provided as a file, so cat <(foo)
becomes as if you'd used foo > /some/file
and cat /some/file
, and tee >(foo)
becomes as if you'd done tee /some/file
and foo < /some/file
. The commands are executed concurrently. Since the output is not seen by the shell, field splitting and wildcard expansion are not a concern.
edited Feb 9 at 2:40
answered Feb 9 at 2:26
muru
33.4k577142
33.4k577142
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422958%2fmisunderstanding-the-purpose-of-a-process-substitution%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password