How to undo exec > /dev/null in bash?

To do it right, you need to copy the original FD 1 somewhere else before repointing it to /dev/null. In this case, I store a backup on FD 5:

exec 5>&1 >/dev/null
...
exec 1>&5

Another option is to redirect stdout within a block rather than using exec:

{
    ...
} >/dev/null

Leave a Comment