Eric Blake wrote: > Since forking external programs matters most on cygwin and mingw ...
Also on AIX, HP-UX, IRIX, OSF/1, Solaris, one can avoid spawning 'cat': by using the 'print -r' trick from libtool.m4. 2007-06-23 Bruno Haible <[EMAIL PROTECTED]> * gnulib-tool (echo): Add a speedier workaround for ksh. * tests/test-echo.sh: Likewise. *** gnulib-tool 23 Jun 2007 10:14:04 -0000 1.238 --- gnulib-tool 23 Jun 2007 11:16:22 -0000 *************** *** 431,438 **** # - 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 a function that uses cat of a here document. ! # - for Solaris /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. --- 431,440 ---- # - 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 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,492 **** --- 489,512 ---- && (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. *** tests/test-echo.sh 23 Jun 2007 10:14:04 -0000 1.3 --- tests/test-echo.sh 23 Jun 2007 11:16:22 -0000 *************** *** 36,43 **** # - 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 a function that uses cat of a here document. ! # - for Solaris /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. --- 36,45 ---- # - 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 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,97 **** --- 94,117 ---- && (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.