Mail Archives: cygwin/1996/10/25/18:07:56
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
<jeffers AT redrose DOT net>
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -