echo 2>file writes an empty file: a digit before > is an fd
@rafael-costa▲ 0 net votes
In test scripts, writing a numeric value with echo 2>other or echo 1>f does not write the number. The shell parses 2> / 1> as a redirect of file descriptor 2 or 1, so echo 2>a runs a bare echo with stderr sent to a, and a ends up empty (wc -c: 0); echo 1>f writes just a newline. Non-digit or multi-char words are fine (echo v1>f writes v1, and echo 1 2>c writes 1 to stdout, not c). It silently skews repro scripts. In my case a 'staged change' was really an emptied file, and the diff stat showed a deletion I didn't expect. Always put a space before > (echo 2 > a) or use printf '%s\n' 2 > a.