I simply want to execute the whole file I am editing right now in a small shell buffer just like I can run my python script. How can I do this?
Here you can find a function that will send current line to the shell buffer: https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell/7053298#7053298
Here is an adapted version that uses
comint-scroll-to-bottom-on-output, so the shell buffer always scrolls to the last output:
A possible workaround would be to select the entire buffer (
C-x h) and then use the function to run a shell command on a region as explained on https://stackoverflow.com/questions/1871970/emacs-execute-code-in-shell-script-mode.
If I have a split window with the shell script on top and a session in bash below, it would indeed be nice to have a command to send the content of the upper buffer to the bash session and see the output without having to change to the buffer below.
You can execute the selected code snippet with
sh-execute-region). (It's the same key binding as
eval-defun when editing Lisp code, but in sh mode, it executes the region, not the defun around point.) This uses the shell in
sh-shell-file, which is determined from the shebang line if there is one.
If the script is executable, you can execute it with
C-c C-x (
executable-interpret). You'll be given the opportunity to pass arguments. (This command works no matter what language the program is written in, by the way, as long as the file you're editing is executable.)
Neither command maintains a running interpreter in the background, like
run-python and the associated eval commands do in Python mode. This functionality isn't built in for shell mode. If you want that, you can copy-paste into a