Make use of ksh's 'print' built-in.
authorBruno Haible <bruno@clisp.org>
Sat, 23 Jun 2007 11:20:11 +0000 (11:20 +0000)
committerBruno Haible <bruno@clisp.org>
Sat, 23 Jun 2007 11:20:11 +0000 (11:20 +0000)
ChangeLog
gnulib-tool
tests/test-echo.sh

index b869adcdd33183bd80b951448893f780bc80f182..8055b38a891e925e7bf64657d2529577198394dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-06-23  Bruno Haible  <bruno@clisp.org>
+
+       * gnulib-tool (echo): Add a speedier workaround for ksh.
+       * tests/test-echo.sh: Likewise.
+
 2007-06-23  Bruno Haible  <bruno@clisp.org>
 
        * gnulib-tool (echo): Add workarounds also for bash versions < 2.04.
index ba865ee03addd69e5e8b53cceffdd59ce770c857..8823abd19765e3920496f145ba96bf6ec5357dbf 100755 (executable)
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2007-06-23 10:14:04 $'
+cvsdatestamp='$Date: 2007-06-23 11:20:11 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 nl='
@@ -431,8 +431,10 @@ func_ln_if_changed ()
 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
 # - for bash < 2.0: define echo to a function that uses cat of a here document.
 # - for zsh: turn sh-emulation on.
+# - for ksh: alias echo to 'print -r'.
 # - for ksh: alias echo to a function that uses cat of a here document.
-# - for Solaris /bin/sh: respawn using /bin/ksh and rely on the ksh workaround.
+# - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
+#   the ksh workaround.
 # - otherwise: respawn using /bin/sh and rely on the workarounds.
 # When respawning, we pass --no-reexec as first argument, so as to avoid
 # turning this script into a fork bomb in unlucky situations.
@@ -487,6 +489,24 @@ if test -z "$have_echo" \
    && (emulate sh) >/dev/null 2>&1; then
   emulate sh
 fi
+# For ksh: alias echo to 'print -r'.
+if test -z "$have_echo" \
+   && (type print) >/dev/null 2>&1; then
+  # A 'print' command exists.
+  if type print 2>/dev/null | grep / > /dev/null; then
+    :
+  else
+    # 'print' is a shell built-in.
+    if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
+      # 'print' is the ksh shell built-in.
+      alias echo='print -r'
+    fi
+  fi
+fi
+if test -z "$have_echo" \
+   && echo '\t' | grep t > /dev/null; then
+  have_echo=yes
+fi
 # For ksh: alias echo to a function that uses cat of a here document.
 # The ksh manual page says:
 #   "Aliasing is performed when scripts are read, not while they are executed.
index b1e40472f569c6e1dcfc9678f3bd29f2b0f40f80..f4c62d14e733a741a9b165a6d1b3882e3d056078 100755 (executable)
@@ -36,8 +36,10 @@ func_fatal_error ()
 # - for bash >= 2.0: define echo to a function that uses the printf built-in.
 # - for bash < 2.0: define echo to a function that uses cat of a here document.
 # - for zsh: turn sh-emulation on.
+# - for ksh: alias echo to 'print -r'.
 # - for ksh: alias echo to a function that uses cat of a here document.
-# - for Solaris /bin/sh: respawn using /bin/ksh and rely on the ksh workaround.
+# - for Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh and rely on
+#   the ksh workaround.
 # - otherwise: respawn using /bin/sh and rely on the workarounds.
 # When respawning, we pass --no-reexec as first argument, so as to avoid
 # turning this script into a fork bomb in unlucky situations.
@@ -92,6 +94,24 @@ if test -z "$have_echo" \
    && (emulate sh) >/dev/null 2>&1; then
   emulate sh
 fi
+# For ksh: alias echo to 'print -r'.
+if test -z "$have_echo" \
+   && (type print) >/dev/null 2>&1; then
+  # A 'print' command exists.
+  if type print 2>/dev/null | grep / > /dev/null; then
+    :
+  else
+    # 'print' is a shell built-in.
+    if (print -r '\told' | grep told > /dev/null) 2>/dev/null; then
+      # 'print' is the ksh shell built-in.
+      alias echo='print -r'
+    fi
+  fi
+fi
+if test -z "$have_echo" \
+   && echo '\t' | grep t > /dev/null; then
+  have_echo=yes
+fi
 # For ksh: alias echo to a function that uses cat of a here document.
 # The ksh manual page says:
 #   "Aliasing is performed when scripts are read, not while they are executed.