expected=$MH_TEST_DIR/$$.expected
actual=$MH_TEST_DIR/$$.actual
-cat > $expected <<EOF
+#
+# Handle different output depending on readline version
+#
+
+set +e
+whatnowtest=`echo cd | TERM=dumb whatnow -prompt ''`
+set -e
+
+case ${whatnowtest} in
+ cd) cat > "$expected" <<EOF
baz
boz
+ls
EOF
+ ;;
+ "") cat > "$expected" <<EOF
+baz
+boz
+EOF
+ ;;
+ *) echo "Unknown response to whatnow readline test"
+ echo "Response is: ${whatnowtest}"
+ exit 1
+ ;;
+esac
cat > $expectederr <<EOF
EOF
# NB use of sort as the order of output of ls is not guaranteed
-echo 'ls' | whatnow -noedit -prompt '' 2> "$actualerr" | sort > "$actual"
+echo 'ls' | TERM=dumb whatnow -noedit -prompt '' 2> "$actualerr" | \
+ sort > "$actual"
+
+check "$expectederr" "$actualerr" 'keep first'
+check "$expected" "$actual" 'keep first'
+
+# Check with SHELL unset. This won't reveal any problems if
+# /bin/sh sets SHELL, which bash does.
+unset SHELL
+
+echo 'ls' | TERM=dumb whatnow -noedit -prompt '' 2> "$actualerr" | \
+ sort > "$actual"
check "$expectederr" "$actualerr"
check "$expected" "$actual"