ksh93 / ksh

ksh 93u+m: KornShell lives! | Latest release: https://github.com/ksh93/ksh/releases
Eclipse Public License 2.0
192 stars 32 forks source link

command substitution here-doc syntax error not entered in history #775

Closed McDutchie closed 3 months ago

McDutchie commented 3 months ago

Reproducer:

$ echo $(( 1 << 8 ) )
-ksh: syntax error at line 1: `<<8' here-document not contained within command substitution

This is as expected: the space between the final ) ) means it's not an arithmetic expansion, so it's treated as a command substitution with a syntax error.

But now, arrow up: the command with the syntax error does not come back for the user to correct it. It has not been added to the history, and that is a bug.

We inherited this bug from 93u+.

McDutchie commented 3 months ago

There are other cases. The following are also not entered into the history.

$ a[]=12
-ksh: syntax error at line 1: `[]' empty subscript
$ function foo $bad { :; }
-ksh: syntax error at line 1: invalid reference list

All of these are omitted from the history because the error message is thrown using a direct errormsg() call without calling sh_syntax(). So the fix should be either to amend sh_syntax() so that it can show these messages, or to keep printing the message separately but also call sh_syntax() and amend it to skip the message in that case.