Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wall uname output: Linux treehug.home.kurahaupo.gen.nz 3.2.0-54-generic #82-Ubuntu SMP Tue Sep 10 20:08:42 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.2 Patch Level: 25 Release Status: release Description: The value of $? after starting a backgrounded command is inconsistent: $? is unchanged after starting a sufficiently complex command, but after starting a simpler command it is set to 0. Determining "sufficiently complex" has been a bit tricky, but it appears to depend only on the type of the top-level node of the parse-tree: An unbracketed conditional chain of pipelines will leave $? set to 0 regardless of the complexity of its components. Likewise invoking a function will leave $? set to 0 no matter how complex the body of the function may be. Conversely, grouping even a single simple command with brackets or using any control structure will leave $? untouched. Repeat-By: ( (exit 42) ; : & echo $? ; wait ) # says 0 ( (exit 42) ; : | : && : || : & echo $? ; wait ) # says 0 ( (exit 42) ; : | if :; then :; fi & echo $? ; wait ) # says 0 ( (exit 42) ; if :; then :; fi & echo $? ; wait ) # says 42 ( (exit 42) ; { : ; } & echo $? ; wait ) # says 42