shell-expand-line and shebangs

In bash, the very useful shell-expand-line (M-C-e) expands command substitutions to their contents, on the current line. However, this works very strangely for commands without shebangs.

One may verify this by the following.

  1. Create a simple executable file with and without shebang.
echo echo hi >> test-no-shebang
chmod +x test-no-shebang
echo '#!/bin/sh' >> test-shebang
echo echo hi >> test-shebang
chmod +x test-shebang
  1. Enter `./test-shebang`, then M-C-e. This works as expected, expanding the line to hi. C-_ works normally, undoing the expansion.
  2. Enter `./test-no-shebang`, then M-C-e. This works strangely, indeed expanding the line to hi, but removing the prompt in front of the line. C-_ does not work, printing the character literally instead, and nor do most bindings, but C-u kind of works, successfully clearing the line (but not clearing the hi).

Why is this the case? Can I make shell-expand-line work for scripts without shebang?