bug-bash
[Top][All Lists]
Advanced

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

Re: question and/or enhancement request


From: Dave Rutherford
Subject: Re: question and/or enhancement request
Date: Sun, 29 Jul 2007 18:36:08 -0400

On 7/29/07, Erick Wodarz <address@hidden> wrote:
>   I think the following is hard (or impossible?) using bash.  I want to
> create a shell script that will ...

This may be possible, depending on exactly what you need,
but you'd probably be better off trying `expect'.

#!/bin/bash

mknod pipe_to_bash p
mknod pipe_to_prog p

# 1.  Execute a program asynchronously, and return it's PID.

# awk program to multiply by 2, output in bash commands
awk '{ print "echo", 2 * $1 ";"}' < pipe_to_prog > pipe_to_bash &
childpid=$!
echo awk is $childpid, this bash is $$

# 2.  Have the program read stdin from the shell's current stdout

# (if you write instead
#  exec 9>&1 < pipe_to_bash > pipe_to_prog,
#  both programs will block)
exec 9>&1 > pipe_to_prog < pipe_to_bash

# give awk some input
echo 5
echo 6
echo 7

exec >&9        # closes pipe_to_prog (reconnecting original stdout)
                # to trigger awk to read input

# 3.  Have the program read write stdout to the shell's current stdin
# (You meant not to say "read", right?)

# read the commands output by awk from stdin
eval `while read w; do echo "$w"; done`
# (". -" would be better here... if it worked.
#  Also tried ". /dev/stdin" without luck.)

rm pipe_to_bash pipe_to_prog

# Dave




reply via email to

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