Summary
The compound redirection pattern { ... } 3>&1 >"$file" does not correctly separate fd3 (→ original stdout) from fd1 (→ file). Content written to fd3 via echo "msg" 1>&3 ends up in the file instead of on the terminal.
Reproduction
{
echo "progress" 1>&3
echo "file content"
} 3>&1 > /tmp/test_fd.txt
cat /tmp/test_fd.txt
# Expected: only "file content"
# Actual: both "progress" and "file content" appear in the file
Context
Discovered while running bashblog via bashkit CLI. Bashblog uses this pattern in all_posts(), rebuild_index(), all_tags(), and make_rss() to show progress dots on the terminal while writing content to a file:
{
echo -n "." 1>&3 # progress dot → terminal
echo "<html>...</html>" # content → file
} 3>&1 >"$contentfile"
Expected behavior
In { ... } 3>&1 >file:
>file redirects fd1 to the file
3>&1 duplicates the original fd1 (terminal) to fd3
- Writing to fd3 via
1>&3 should go to the terminal, not the file
The fd3 dup should capture the original stdout before the >file redirect is applied.
Summary
The compound redirection pattern
{ ... } 3>&1 >"$file"does not correctly separate fd3 (→ original stdout) from fd1 (→ file). Content written to fd3 viaecho "msg" 1>&3ends up in the file instead of on the terminal.Reproduction
{ echo "progress" 1>&3 echo "file content" } 3>&1 > /tmp/test_fd.txt cat /tmp/test_fd.txt # Expected: only "file content" # Actual: both "progress" and "file content" appear in the fileContext
Discovered while running bashblog via bashkit CLI. Bashblog uses this pattern in
all_posts(),rebuild_index(),all_tags(), andmake_rss()to show progress dots on the terminal while writing content to a file:{ echo -n "." 1>&3 # progress dot → terminal echo "<html>...</html>" # content → file } 3>&1 >"$contentfile"Expected behavior
In
{ ... } 3>&1 >file:>fileredirects fd1 to the file3>&1duplicates the original fd1 (terminal) to fd31>&3should go to the terminal, not the fileThe fd3 dup should capture the original stdout before the
>fileredirect is applied.