* Eric Blake wrote on Wed, Sep 08, 2010 at 03:12:48AM CEST: > $ /bin/sh -c 'alias 2>/dev/null' > alias: Not found > $ /bin/sh -c '(alias) 2>/dev/null' > $ /bin/sh -c 'exec 3>&2; exec 2>/dev/null; unalias echo; exec 2>&3; > exec 3>&-' > $ > > the indirect redirection of stderr prior to attempting the unfound > command does indeed work to silence the message, without costing a > subshell (hmm, maybe autoconf should use that trick to reduce > forking at m4sh startup).
exec 3>&2 2>/dev/null; command; exec 2>&3 3>&- has the advantage of not forking, the disadvantage of using another file descriptor (which we should probably disallow the user from passing in). With modern shells, it should work just as well to { command; } 2>/dev/null except of course, really old shells will fork a subshell in order to execute redirected compound commands, so unless we have some indication that this was fixed before some other feature we rely on was fixed ;-) we might need a test for that. I expect that some shells try to optimize (command) 2>/dev/null by not always executing command in a subshell (that would explain some of the bugs old dash had), but I don't know how common that is. builtin vs. external command are a potential difference, too, also for old shell behavior. Cheers, Ralf