Sample Header Ad - 728x90

shell-expand-line and shebangs

1 vote
1 answer
118 views
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
2. Enter ` ./test-shebang , then M-C-e. This works as expected, expanding the line to hi. C-_` works normally, undoing the expansion. 3. 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? EDIT: 1. Some comments thought that it would be wise for me to mention that the mentioned key-bindings refer to the emacs line-editing bindings (which are the default bash key-bindings). 2. With more testing, I observe that I can reproduce the problem on the mac Terminal and on kitty on bash version 5.2.15(1)-release, but cannot reproduce the problem on bash 3.2.57(1)-release.
Asked by user22476690 (143 rep)
Aug 4, 2024, 08:35 AM
Last activity: Aug 5, 2024, 07:38 PM