That behaviour has nothing to do with bash (or any shell for that matters). It's the terminal device driver that pauses output (stops sending data to the terminal) when it receives the ^S
character (or whatever is set by stty stop
) from the terminal.
Applications started by your shell in that terminal won't see that ^S
character even if they read from the terminal device.
The shell is just another application that runs in the terminal and whose job is just to interpret command lines and start the corresponding command in separate processes. While the commands are running, the shell does nothing, it just waits for them to finish so it can prompt you for another command to enter.
Actually, modern shells including bash
disable that flow control process when they (their command line editor) interacts with the terminal device. You'll notice that when you press Ctrl+S at the bash prompt, and assuming it's in emacs
mode, bash
handles it as an incremental search widget invocation.
Here for a message to be issued when you press Ctrl+S, it's the terminal device driver (line discipline) that you would need to modify. It feels a bit silly though to be sending something in a reply to the terminal sending "Please stop sending".
Another approach could be to wrap your shell session into some pseudo-terminal wrapper that puts the host terminal device in raw mode and offers its own pseudo-terminal device to bash
, intercepts those ^S
character to write the message.
That could be done with GNU screen for instance which is a terminal emulator within a terminal.
Add to your ~/.screenrc
:
bindkey "\023" eval 'hstatus "Stopped - press Ctrl+Q to proceed"' xoff
bindkey "\021" eval "hstatus screen" xon
Here with the message issued in the hardstatus line of your terminal.
bash
(or any shell for that matters). It's the terminal device driver that pauses output when it receives the^S
character from the terminal. – Stéphane Chazelas Oct 06 '20 at 07:15less
) or run it inside something with scrollback such asscreen
ortmux
? – Chris Davies Oct 06 '20 at 08:20