Subject: Re: Broken stdin?
From: [email-masked] (Weiqi Gao)

26 Oct 1996 07:04:47 -0700
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Sender: [email-masked]
X-Mailer: Windows Eudora Light Version 1.5.2
Original-To: [email-masked]
Original-Sender: [email-masked]

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 <stdio.h>
> 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
[email-masked]

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".