# redirect STDOUT to a file in a subshell

**URL:** <https://community.unix.com/t/redirect-stdout-to-a-file-in-a-subshell/270391>\
**Category:** Shell Programming and Scripting\
**Created:** [July 28, 2010, 4:25am UTC](https://community.unix.com/t/redirect-stdout-to-a-file-in-a-subshell/270391 "2010-07-28T04:25:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnvee](https://community.unix.com/letter_avatar/tnvee/32/5_5575768a8748004e209b776fc1b2916d.png) [@tnvee](https://community.unix.com/u/tnvee)\
**Post date:** [July 28, 2010, 4:25am UTC](https://community.unix.com/t/redirect-stdout-to-a-file-in-a-subshell/270391/1 "2010-07-28T04:25:47Z")

</div>

Hi,

I would like to avoid re-directing line by line to a file.

What is the best way to re-direct STDOUT to a file in a subshell?

Thanks in advance.

Cheers  
Vj

---

<div class="post-metadata">

**Author:** ![pludi](https://community.unix.com/user_avatar/community.unix.com/pludi/32/1278_2.png) [@pludi](https://community.unix.com/u/pludi)\
**Post date:** [July 28, 2010, 4:40am UTC](https://community.unix.com/t/redirect-stdout-to-a-file-in-a-subshell/270391/2 "2010-07-28T04:40:21Z")

</div>

Put

```nohighlight
exec >/path/to/file

```

somewhere near the beginning of the file. Or

```nohighlight
exec 3>&1
exec >/path/to/file

```

if you want to still be able writing to the original output channel later by using FD 3 instead of 1.
