From: weiqigao AT crl DOT com (Weiqi Gao) Subject: Re: Broken stdin? 26 Oct 1996 07:04:47 -0700 Sender: daemon AT cygnus DOT com Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <199610261318.AA08022.cygnus.gnu-win32@mail.crl.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Sender: weiqigao AT mail DOT crl DOT com X-Mailer: Windows Eudora Light Version 1.5.2 Original-To: gnu-win32 AT cygnus DOT com Original-Sender: owner-gnu-win32 AT cygnus DOT com At 04:45 PM 10/25/96 -0700, you wrote: > > Is stdin broken in bash? The following c program > was tested using the bash shell... > >test.c > > #include > char line[100]; > int value; > > main() > { > (void) printf("Enter a value: "); > (void) fgets(line, sizeof(line), stdin); > (void) sscanf(line, "%d", &value); > (void) printf("Twice %d is %d\n", > value, value * 2); > return (0); >} > >This should allow the user to enter a value, but instead >the program produces the following: > >$ test >$ Enter a value: >$ Twice 0 is 0 > >The program 'returns' even though no "\n" is added. >Out of curiosity I also tested a shell script version >of the same program: > >test.sh > >echo -n 'Enter a value:' >&2 >read ans >echo "$ans" > >This produces: > >$ Enter a value: > >$ > >The shell script also returns without waiting for a response. >The test.c program, however, does work correctly using the dos >shell. I'd be grateful to learn how these programs perform >on other users machines using bash. > The bash shell (under Windows 95 at least) is broken in this respect. It interprets the enter key at the end of the command line as two enter keys. I posted a similar problem with "rm -i foo.bar" a couple of days ago. This has to be one of the DOS/UNIX CR-LF vs. LF problems. A remedy posted yesterday suggests using "Ctrl-J" key instead of "Enter". I also seem to remember with "less" in beta 14, when I want to leave it, I have to press "q, Enter" which exits the program and gives me FOUR prompts afterwards. -- Weiqi Gao weiqigao AT crl DOT com - For help on using this list, send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".