cadet/loopcheck.sh: still bash, leaving only PIPESTATUS
authorng0 <ng0@n0.is>
Sat, 9 Mar 2019 11:26:07 +0000 (11:26 +0000)
committerng0 <ng0@n0.is>
Sat, 9 Mar 2019 11:26:07 +0000 (11:26 +0000)
src/cadet/loopcheck.sh

index ddc8c191c246909c460401b7332999033e280135..9b867e95b796d5baf0eb3102b9d157b5cd1b49b5 100755 (executable)
@@ -1,4 +1,41 @@
-#!/bin/sh
+#!/usr/bin/env bash
+# This script is in the public domain
+# POSIX shell solution for named pipes and pipestatus,
+# http://shell.cfajohnson.com/cus-faq-2.html#Q11
+# run() {
+#     j=1
+#     while eval "\${pipestatus_$j+:} false"; do
+#         unset pipestatus_$j
+#         j=$(($j+1))
+#     done
+#     j=1 com= k=1 l=
+#     for a; do
+#         if [ "x$a" = 'x|' ]; then
+#             com="$com { $l "'3>&-
+#                          echo "pipestatus_'$j'=$?" >&3
+#                        } 4>&- |'
+#             j=$(($j+1)) l=
+#         else
+#             l="$l \"\$$k\""
+#         fi
+#         k=$(($k+1))
+#     done
+#     com="$com $l"' 3>&- >&4 4>&-
+#                     echo "pipestatus_'$j'=$?"'
+#     exec 4>&1
+#     eval "$(exec 3>&1; eval "$com")"
+#     exec 4>&-
+#     j=1
+#     while eval "\${pipestatus_$j+:} false"; do
+#         eval "[ \$pipestatus_$j -eq 0 ]" || return 1
+#         j=$(($j+1))
+#     done
+#     return 0
+# }
+
+# # https://mywiki.wooledge.org/Bashism has another solution:
+# # mkfifo fifo; command2 <fifo & command1 >fifo; echo "$?"
+
 while true; do
     if [ "$1" = "" ]; then
        echo All
@@ -7,6 +44,7 @@ while true; do
        echo One
        LOGFILE="test_`date "+%m.%d-%H:%M:%S"`.log"
        taskset 01 $1 2>&1 | tee $LOGFILE | grep -v DEBUG;
+        # TODO: Replace $PIPESTATUS with more portable code
        if [ "${PIPESTATUS[0]}" != "0" ]; then
            echo "Failed";
            date;
@@ -15,5 +53,5 @@ while true; do
     fi
     grep cadet test_*.log | grep -B 10 ERROR && break
     grep cadet test_*.log | grep -B 10 Assert && break
-    ls core* &> /dev/null && break
+    ls core* > /dev/null 2>&1 && break
 done