Jim Meyering <[email protected]> writes:
> Bruce Korb wrote:
>> Does that "git diff-index" really need to be run in a separate
>> shell invocation?
>>> dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty=
>
> Yes. As I recall, that was required in order to ensure that even when
> the shell fails to find a "git" program, the stderr output
> is redirected.
What the Autoconf manual says about this is:
On the other hand, some shells, such as Solaris or FreeBSD
`/bin/sh', warn about missing programs before performing redirections.
Therefore, to silently check whether a program exists, it is necessary
to perform redirections on a subshell:
$ /bin/sh -c 'nosuch 2>/dev/null'
nosuch: not found
$ /bin/sh -c '(nosuch) 2>/dev/null'
$ bash -c 'nosuch 2>/dev/null'
I always understood the use of "sh -c" in these examples as a
device to show which shell was being invoked, not to advise
actually using "sh -c". Rather, I thought that the advice was to
put the invocation in a subshell, as "(nosuch) 2>/dev/null".
--
Only wimps use tape backup: _real_ men just upload their important stuff
on ftp, and let the rest of the world mirror it ;)
-- Linus Torvalds