bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why does a Bash shell script write prompts followed by reads and do it r


From: Robert Parker
Subject: Why does a Bash shell script write prompts followed by reads and do it right?
Date: Mon, 31 Aug 2015 23:25:31 +0700

A trivial script example that just works:

#!/bin/bash
# echo a prompt and write the user's response to a file.

echo "Enter variable name: "
read ans
echo "$ans" > tmpfil
echo "Enter variable type: "
read ans
echo "$ans" >> tmpfil
echo "Enter variable default value: "
read ans
echo "$ans" >> tmpfil
echo "Beginning with an assignmment operator"
echo "Enter C code for this option:"
read ans
echo "$ans" >> tmpfil

Yet when I attempt the same in a C program, the system always writes 2 prompts, then waits for a read.
Does not matter if I write(1, "..."); read(0, number, buffer); or use fputs("...", stdout); fgets(.....
The result is the same.
And I have tried using readline without any better result.

I have downloaded the source code for Bash.
Would someone please let me know where to look to learn to make my code work like yours?

Thanks, Bob


--
The Bundys, Cliven, Ted and Al. Great guys to look up to.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]