Problem
The redirect combination 2>&1 >file inside command substitution doesn't follow bash's left-to-right evaluation order.
Expected behavior (real bash):
2>&1 — stderr is redirected to where stdout currently points (the $() capture pipe)
>file — stdout is redirected to the file
So result=$(cmd 2>&1 >file) should capture stderr in result and write stdout to file.
Actual behavior (bashkit): Both stdout and stderr go to the file; result is empty.
Reproduction
f() { echo "stdout"; echo "stderr" >&2; }
result=$(f 2>&1 >"/tmp/out.txt")
echo "result=[$result]"
cat /tmp/out.txt
Real bash: result=[stderr], file contains stdout
Bashkit: result=[], file contains stdout\nstderr
Impact
The wedow/ticket cmd_link uses this pattern to capture awk's stderr count output while writing the modified file to a temp file:
result=$(awk '...' "$file" 2>&1 >"${file}.tmp")
# result should get the count from: END { printf "%d", added > "/dev/stderr" }
# file.tmp should get the modified file content
With bashkit, result is always empty, so ((count += result)) fails.
Problem
The redirect combination
2>&1 >fileinside command substitution doesn't follow bash's left-to-right evaluation order.Expected behavior (real bash):
2>&1— stderr is redirected to where stdout currently points (the$()capture pipe)>file— stdout is redirected to the fileSo
result=$(cmd 2>&1 >file)should capture stderr inresultand write stdout tofile.Actual behavior (bashkit): Both stdout and stderr go to the file;
resultis empty.Reproduction
Real bash:
result=[stderr], file containsstdoutBashkit:
result=[], file containsstdout\nstderrImpact
The wedow/ticket
cmd_linkuses this pattern to capture awk's stderr count output while writing the modified file to a temp file:With bashkit,
resultis always empty, so((count += result))fails.