From 4dcba48c8c6d9a111fbbc18da4e0ae8e5c1f16fb Mon Sep 17 00:00:00 2001 From: mappu Date: Thu, 3 Dec 2015 10:24:02 +0000 Subject: [PATCH] commit all archived files --- README.md | 18 +++++++++++++++++ dist-archive/mini-expect.v1.sh | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 README.md create mode 100644 dist-archive/mini-expect.v1.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..afff716 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# mini-expect + +![](https://img.shields.io/badge/written%20in-bash-blue) + +An expect(1) clone that doesn't corrupt CR bytes. + +I recently attempted to use expect(1) as part of a test suite, but it seems totally incapable of sending 0x13 bytes without corrupting them into 0x10. Maybe it was my terminal mode (but `echo $'\r' | nc` was fine), maybe it was my expect/tcl installation (but the bug was observed on current packages from both Cygwin and Debian), maybe it was easier to reimplement the basic functionality instead of spending any more time on that. + +## Usage + +`source mini-expect.sh` + +Then, use spawn/send/expect/interact commands just like with expect(1). + + +## Download + +- [⬇️ mini-expect.v1.sh](dist-archive/mini-expect.v1.sh) *(474B)* diff --git a/dist-archive/mini-expect.v1.sh b/dist-archive/mini-expect.v1.sh new file mode 100644 index 0000000..d09bc85 --- /dev/null +++ b/dist-archive/mini-expect.v1.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Mini expect(1) clone that doesn't mangle \r into \n. +# + +EXPECT_IN=0 +EXPECT_OUT=1 + +spawn() { + coproc "$@" + EXPECT_IN=${COPROC[0]} + EXPECT_OUT=${COPROC[1]} +} + +expect() { + local expect_str="$1" + while read -r line <&${EXPECT_IN} ; do + echo "$line" + if [[ $line =~ $expect_str ]] ; then + return + fi + done +} + +send() { + echo -n "$@" + echo -n "$@" >&${EXPECT_OUT} +} + +send_pipe() { + local buffer="$(cat)" + send "$buffer" +} + +interact() { + cat >&${EXPECT_OUT} +}