0

I couldn't understand the difference between command grouping and pipelining

3

1 Answer 1

5

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .