4

I have some scripts which use coproc to control stdout/stdin of subprocesses. Unfortunately, coproc was introduced in Bash 4.0, and on many systems I use, there is an earlier versions of bash.

Are there any alternatives to coproc?

MadHatter
  • 78,442
  • 20
  • 178
  • 229
  • Bash has a lot more severe, unexplained limitations as well. I think, you are on the point when you should leave it and use some other (maybe perl or python were good choices in your place). – peterh Feb 18 '14 at 14:39
  • @PeterHorvath, that is true, but bash is the only "language" which is common for all platforms. I try to write my script for the common denominator rather than maintaining different versions of it. – Dog eat cat world Feb 18 '14 at 14:42
  • Perl also exists everywhere. And you can see, that also bash isn't really uniform everywhere. – peterh Feb 18 '14 at 14:44
  • 1
    -bash: perl: command not found – Dog eat cat world Feb 18 '14 at 14:46
  • 1
    You have right, I am really sorry. – peterh Feb 18 '14 at 14:47

1 Answers1

6

You can used standard named pipe instead of coproc:

mkfifo in_data out_data

command <in_data >out_data &

exec 3> in_data 4< out_data

echo <some thing here> >&3
read <some variables here> <&4
cuonglm
  • 2,346
  • 2
  • 15
  • 20
  • Warning: This works, but is surprisingly buffered. All the tricks like `stdbuf -o0 {bash_script}` to disable this buffering, rely on external tools that are generally only available on Linux. – Andy Feb 24 '20 at 15:47