[colug-432] bash pipe + read?
Rick Hornsby
richardjhornsby at gmail.com
Mon Nov 16 11:33:43 EST 2015
> On Nov 16, 2015, at 10:25, Jeff Frontz <jeff.frontz at gmail.com> wrote:
>
>
> On Mon, Nov 16, 2015 at 10:38 AM, Rick Hornsby <richardjhornsby at gmail.com <mailto:richardjhornsby at gmail.com>> wrote:
> I think I understand the problem - what's happening is that because there's an input pipe to bash, read takes the next line of the script as its input instead of taking it from the user - they're both on stdin.
>
> If I understand your question/scenario, you probably want to redirect your read from /dev/tty (a la "$ read < /dev/tty someVariable"). You can also use the tty command to figure out if there is actually a tty associated with the shell (e.g., to provide some useful default behavior if the script is run from, say, a crontab or at job).
This particular script will always be run interactively. The tasks it accomplishes may later be rolled into a kickstart type thing, but at that point I'll be looking at a rewrite and the need for a prompt will go away.
The /dev/tty thing looks perfect, and appears in my little test stub to be doing exactly what I need. It makes sense why it works, but I hadn't thought of that.
This is a very simple solution that's extremely readable - far more than the fork inversion things.
thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20151116/97b9e7cf/attachment.html
More information about the colug-432
mailing list