On 07/31/2010 06:18 PM, Adam Thompson wrote:
Inside a shell script, I want to start a persistent mysql client process and feed it commands one by one.
I’d like to use a named pipe, but the only way I’ve found to do it so far is with a subshell, by putting 99% of the script inside the subshell and piping the subsell’s entire output to mysql. While this more-or-less works, it’s very much not ideal.
Anyone have any better ideas?
I think you want something like this.
exec 5>&1 # "save" stdout as fd 5 exec >/tmp/mypipe # redirect stdout to pipe echo "Command 1" # goes to pipe echo "Command 2" # goes to pipe # etc etc etc exec 1>&5 5>&- # restore stdout, close fd 5
Peter