0

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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.