[Openvpn-devel] [PATCH v3] t_client.sh.in: Use printf instead of echo -e

Gert Doering <[email protected]>
Newsgroups net.sourceforge.lists.openvpn-devel
Message-ID <[email protected]>
From: Frank Lichtenheld <[email protected]>

In some shells the echo builtin doesn't interpret -e as
an argument, it just outputs it as a string.

Examples for shells I have observed this with are dash on
Ubuntu and /bin/sh on macOS.

Use printf instead which should have better consistency
across shells and operating systems.

Change-Id: I746bd8c0fa3496d23569cde496438fc4189600fe
Signed-off-by: Frank Lichtenheld <[email protected]>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1753
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1753
This mail reflects revision 3 of this Change.

Acked-by according to Gerrit (reflected above):

        
diff --git a/tests/t_client.sh.in b/tests/t_client.sh.in
index 7233187..0254c0c3 100755
--- a/tests/t_client.sh.in
+++ b/tests/t_client.sh.in
@@ -132,21 +132,20 @@
 {
     case $V in
 	0) outbuf="" ;;			# no per-test output at all
-	1) echo -e "$@"			# compact, details only on failure
+	1) printf "$@\n"			# compact, details only on failure
            outbuf="\n" ;;
-	*) echo -e "\n$@\n" ;;		# print all, with a bit formatting
+	*) printf "\n$@\n" ;;		# print all, with a bit formatting
     esac
 }
 
 output()
 {
-    NO_NL=''; if [ "X$1" = "X-n" ] ; then NO_NL=$1 ; shift ; fi
+    END_NL="\n"; if [ "X$1" = "X-n" ] ; then END_NL="" ; shift ; fi
     case $V in
 	0) ;;				# no per-test output at all
-	1) outbuf="$outbuf$@" 		# print details only on failure
-	   test -z "$NO_NL" && outbuf="$outbuf\n"
+	1) outbuf="$outbuf$@${END_NL}"	# print details only on failure
            ;;
-	*) echo -e $NO_NL "$@" ;;	# print everything
+	*) printf "$@${END_NL}" ;;	# print everything
     esac
 }
 
@@ -340,7 +339,7 @@
         else
             output "skip check failed, SKIP test $SUF."
 	    SUMMARY_SKIP="$SUMMARY_SKIP $SUF"
-	    echo -e "$outbuf" ; continue
+	    printf "$outbuf" ; continue
         fi
     fi
 
@@ -361,7 +360,7 @@
 	fail "make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF."
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=31
-	echo -e "$outbuf" ; continue
+	printf "$outbuf" ; continue
     fi
 
     pidfile="${top_builddir}/tests/$LOGDIR/openvpn-$SUF.pid"
@@ -407,7 +406,7 @@
 	trap - 0 1 2 3 15
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
-	echo -e "$outbuf" ; continue
+	printf "$outbuf" ; continue
     fi
 
     # make sure openvpn client is terminated in case shell exits
@@ -470,15 +469,15 @@
 	SUMMARY_OK="$SUMMARY_OK $SUF"
     else
 	if [ "$V" -gt 0 ] ; then
-	    echo -e -n "$outbuf"
-	    echo -e "test run $SUF: $fail_count test failures. FAIL.\n"
+	    printf "$outbuf"
+	    echo "test run $SUF: $fail_count test failures. FAIL."
         fi
 	SUMMARY_FAIL="$SUMMARY_FAIL $SUF"
 	exit_code=30
     fi
 
     if [ -n "$test_cleanup" ]; then
-        echo -e "cleaning up: '$test_cleanup'"
+        echo "cleaning up: '$test_cleanup'"
         eval $test_cleanup
     fi
 


_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.