Pulseaudio, or pure ALSA? Pulseaudio is easiest: Create a dummy sink
pacmd load-module module-null-sink sink_name=tmpsink
and let program 1 output to it. Program 2 reads from the tmpsink.monitor source. And so on. All this can be scripted. pacmd help shows more commands that may be useful, e.g. list-sink-inputs, list-source-outputs, or move-sink-input and move-sink-output if you can't specify sources and sinks for the programs on the commandline.