I couldn't understand the difference between command grouping and pipelining
1 Answer
The differences between these are:
( foo; bar; )
It will execute the commands in a subshell
, so if you made any changes in the subshell they will not appear outside the subshell
. Like
i=2; ( ((i++)); echo $i ); echo $i
You will get output:
3
2
If you do the same thing in { }
then it will be executed in the same environment, so the changes will matter. Like
i=2; { ((i++)); echo $i; }; echo $i
will give:
3
3
Now let's come to pipelining, pipelining is used to take input and give output to some commands.So the command:
a | b
the output of command a
will be given as an input to command b
.
echo "hi" | cat
will give you output hi
.
So output of echo "hi"
i.e. hi
will be input of cat
command.
foo ; bar
or{ foo; bar;}
? Can you provide specific commands that you're confused about ?