On Mon, Aug 21, 2023 at 09:19:00AM +0700, Max Nikulin wrote: > On 21/08/2023 01:48, Greg Wooledge wrote: > > Some shell features do change over time, but the significant > > ordering of redirections has remained stable ever since the original > > Bourne shell. > > An exercise that relies on order of redirections and thus demonstrates its > importance: > > Swap stderr and stdout of a shell command.
Hmm. I thought <https://mywiki.wooledge.org/BashFAQ/047> might have it, but it doesn't. Some examples are pretty close, but none are an exact match. cmd 3>&1 1>&2 2>&3 3>&- Obviously this relies on FD 3 not being in use at that point. In pure sh, you'd need to have knowledge of *some* FD number which is available. In bash, you can use {somevar}>&1 to let the shell pick an FD for you, but that's an extension. cmd {fd}>&1 1>&2 2>&$fd {fd}>&-