Subject: Broken stdin?
From: [email-masked] (David Jeffers)

25 Oct 1996 18:07:56 -0700
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Original-To: [email-masked]
Original-Sender: [email-masked]

 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.
 
-- 

    David Jeffers	    
<[email-masked]>

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