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.
- 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
- Enter
`./test-shebang`
, thenM-C-e
. This works as expected, expanding the line tohi
.C-_
works normally, undoing the expansion. - Enter
`./test-no-shebang`
, thenM-C-e
. This works strangely, indeed expanding the line tohi
, but removing the prompt in front of the line.C-_
does not work, printing the character literally instead, and nor do most bindings, butC-u
kind of works, successfully clearing the line (but not clearing thehi
).
Why is this the case? Can I make shell-expand-line work for scripts without shebang?