This is naive and dirty but it's what I use: I pass different `command lines' to sam by using different arguments. It can be done better for sure but I didn't bother. hth #!/bin/rc t=/tmp/ssam.$pid fn exit () { rm -f $t } cat > $t { for (c in $*) echo $c echo q } | sam -d $t >[2] /dev/null rm -f $t