raner wrote: > > Is there a way to configure bash to echo back each character that was sent > to it's stdin? >
All right, I spent quite some time with this problem, so I thought I share what I've found out and answer my own question. First of all, I should probably rephrase my original question. The real issue here is: How can I enable input echoing for a Solaris bash that is not connected to a terminal? I installed bash 3.2 on Solaris and compared the results with Cygwin bash 3.2 on Windows XP. When launched by my Java application, the Cygwin bash will echo the user input, and the Solaris bash will not. I looked at the bash source code and found out that the input echoing is done by GNU readline. If you search rltty.c for the variable readline_echoing_p you will see that it is initialized based on the ECHO flag in the terminal's TIOTYPE structure (which is just an alias for struct termio/termios). As the bash process is not connected to a terminal in my case (the original root of the problem), I assume that the struct termio/termios is probably all zero/undefined and doesn't have the ECHO flag set. Something like that, I didn't really dig into the details. It looks like, on Solaris, bash will not echo its input unless it is connected to a terminal. If someone in fact does know a way to achieve this, I'd still like to hear it, though. So, what is the work-around? Under Solaris, the situation can be summarized as "No terminal, no echo". So, to get echo to work, we need to run bash with a terminal, or to be more precise, with a pseudo-terminal. I was under the illusion that there would be a simple Solaris command to create a pseudo-terminal (maybe something like "pty bash"), but, of course, there isn't. After googling around a bit, I found a utility called "empty" (http://empty.sf.net). It is designed for a slightly different purpose than what I needed, but it can execute a command in a pseudo-terminal and makes stdin/stdout available as named pipes. To run a bash with a pseudo-terminal in my Java application, I had to write a little script that I called ptybash: #!/bin/sh ./empty -f -i pty.in -o pty.out bash -i cat -u <pty.out & cat -u >pty.in The script uses empty to create the pseudo-terminal and the named pipes. To connect the current stdin/stdout with the pipes, it uses two separate cat commands. My Java application now doesn't just launch bash but instead: bash ptybash The first bash, of course, will still suffer from the echo issue, but it only serves to run the ptybash script, which launches a second bash in a pseudo-terminal. That second bash should have its input echoing intact. Or so I thought... Because, when I tried it, again, all my typed commands were dutyfully executed, but I still couldn't see what I typed. However, now that the bash was running in a terminal, I could actually type: stty echo And after this, I could finally see what I typed, and the completion also showed me the completed filenames. It's a little bit nonstraightforward, but it solved the problem. Does anybody know of an easier way to do this? -- View this message in context: http://www.nabble.com/Bash-command-completion-when-not-connected-to-a-terminal-tf3876564.html#a11022070 Sent from the Gnu - Bash mailing list archive at Nabble.com. _______________________________________________ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash