nico raffo wrote: > I'm writing a simple terminal emulator (on linux using standard pty > libraries) and have run across some behavior in bash that I cannot > explain after several weeks of reading documentation.
I am not sure of the exact cause of your trouble. But having been a few days and no one else suggesting anything I thought I would jump in anyway. Hopefully you will be using a free license on your code? And then you could post it and perhaps someone might see something in it then. > However with bash, the shell doesn't respond at all until a > <CR> is sent, and then bash only sends the output of the command, not > the command itself. If my terminal emulator is expecting the shell to > provide all display text, it wouldn't show the commands at all. This seems like you are tripping into the difference between different tty driver settings of raw mode and canonical input mode (aka cooked mode). In raw mode every character is passed through but in canonical input mode they are buffered up by the tty driver until a full line is present and then the line of characters is sent through. While buffered the characters may be edited by the tty driver editing characters. See the output of 'stty -a' for a list but notably erase DEL, kill ^U, werase (word-erase) ^W. I am probably using imprecise descriptions here since it has been many years since I have coded in this area but hopefully it is good enough. > In all other ways, bash behaves like an interactive shell. My ...rc > files are used correctly, and I can effectively launch and interact > with other programs. As I recall bash behaves differently in interactive mode versus non-interactive mode in that it will save the state of the tty settings, enter raw mode and use libreadline for line editing, then restore the tty state just before invoking the command line action. This has the appearance of being in canonical input mode to programs like stty but actually uses libreadline in raw mode for editing. But again I am probably wrong with this description. You will likely need to know the behavior to understand your problem. > The oddest part of all is that bash will start behaving like zsh if I > run zsh, then exit back to bash, even though it's still the same > process with the same environment. > > Can anyone explain why bash is operating in one mode or the other, and > how I can explicitly set this behavior one way or the other? Try invoking bash with the -i option forcing interactive behavior. Does this change anything? Bob