The command printing code can fail to add a required semicolon when the last word in the command ends with `&'
$ bash --pretty-print <<<$'{ \&;}' { \& } $ f() { if echo \&; then :; fi; } $ declare -f f f () { if echo \& then :; fi } $ eval "$(declare -f f)" bash: syntax error near unexpected token `fi' --- diff --git a/print_cmd.c b/print_cmd.c index 29870837..961c8dae 100644 --- a/print_cmd.c +++ b/print_cmd.c @@ -1446,8 +1446,10 @@ indent (int amount) static void semicolon (void) { - if (command_string_index > 0 && - (the_printed_command[command_string_index - 1] == '&' || + if ((command_string_index > 1 && + the_printed_command[command_string_index - 2] == ' ' && + the_printed_command[command_string_index - 1] == '&') || + (command_string_index > 0 && the_printed_command[command_string_index - 1] == '\n')) return; cprintf (";")