The attached patch "fixes" this: hp% ./bash -c 'time (TIMEFORMAT=y)' real 0m0.001s user 0m0.000s sys 0m0.000s hp% bash -c 'time (TIMEFORMAT=y)' y
Disclaimer: I don't know if it's a good patch. It may break stuff. This problem is caused due to bash passing `time ( ... )' as a COMMAND with type = cm_subshell and flags = CMD_TIME_PIPELINE to execute_command_internal, but since the case to handle type = cm_subshell is before the case to handle flags = CMD_TIME_PIPELINE, the program forks, the time_command is executed inside the new process and we all know what happens next. My patch just adds a special case for this situation, and passes the command directly to time_command. I guess it might be better to just move the block of code handling the general case when flags = CMD_TIME_PIPELINE, but I don't know if this will have any undesired consequences.
diff --git a/execute_cmd.c b/execute_cmd.c index def409f..9e17386 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -588,6 +588,13 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, if (command->type == cm_subshell && (command->flags & CMD_NO_FORK)) return (execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close)); +#if defined (COMMAND_TIMING) + if (command->type == cm_subshell && command->flags & CMD_TIME_PIPELINE) + { + return time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close); + } +#endif /* COMMAND_TIMING */ + #if defined (COPROCESS_SUPPORT) if (command->type == cm_coproc) return (execute_coproc (command, pipe_in, pipe_out, fds_to_close));