This code snippet is from Advanced Bash Scripting Guide.# Redirecting only stderr to a pipe.exec 3>&1                              # Save current value of stdout.ls -l 2>&1 >&3 3>&- | grep bad 3>&-    # Close fd 3 for 'grep' (but not 'ls').#              ^^^^   ^^^^exec 3>&-                              # Now close it for the remainder of the script.# Thanks, S.C.The comments explains the code closes fd 3 only for 'grep'. but the closes fd 3 twice. Why we need to do like this? Is it wrong to close fd 3 only one time for 'grep' like this?ls -l 2>&1 >&3 | grep bad 3>&-    
Redirecting only stderr to a pipe
bash;shell;io redirection;file descriptors