Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't figure it out. As I read in documentaion, {} doesn't create a subshell. However, looks like that sometimes it does:

  $ unset T; echo "T_bfr=$T"; echo $$; { echo $$; export T=1; }; echo "T_afr=$T"

 $ unset T; echo "T_bfr=$T"; echo $$; { echo $$; export T=1 ; }|cat; echo "T_afr=$T"

What is the difference? Why T is missing in the second case?

share|improve this question
up vote 2 down vote accepted

The second case is different because that pipe runs in a subshell, where T_aft=$T is unset.

share|improve this answer
But why pipe with subshell wipes variable from curly braces? – rush Dec 11 '12 at 11:43
Good question. The short answer is that the subshell is unaware of the newly set variable. Long answer - mywiki.wooledge.org/BashGuide/InputAndOutput#Pipes – lurker Dec 11 '12 at 12:11
You may wish to expand your answer with the comment you've given. – EightBitTony Dec 11 '12 at 15:14
See BashFAQ 24 about pipes, subshells, and shell variables. – jw013 Dec 11 '12 at 15:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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