bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: noisy gnulib-tool on IRIX


From: Eric Blake
Subject: Re: noisy gnulib-tool on IRIX
Date: Wed, 08 Sep 2010 07:46:22 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.2

On 09/08/2010 02:44 AM, Bruno Haible wrote:
Hi Eric,

hence the common idiom of first checking if alias/unalias exist using
a subshell check, and if so then using them in the parent shell.

Ah, I didn't think of this trick. But as you noticed, the trick I've found
is more efficient, so I'll use it.

Actually, you've already used that trick - look earlier in gnulib-tool where you set an alias for sed, but only when alias is supported.

Well, the code is clear: We know we have to handle ksh without re-execing,
and in ksh the solution is to use an alias to a shell function that invokes
'cat'. If we're not in ksh, then the code notices it by the fact that the
'alias' command did not work, and tries to re-exec. Which code path does it
end up taking on IRIX (i.e. what's the result when you add a 'set -x'
command at the top of gnulib-tool)?

Hmm - gnulib-tool is another shell script where preserving -v and -x into a re-exec'd invocation might be nice. At any rate, here's the full trace, showing that /bin/sh is ultimately rejected and the script rerun under ksh for IRIX.

# The workaround is: define echo to a function that uses the printf built-in.
have_echo=
have_echo=
if echo '\t' | grep t > /dev/null; then
  have_echo=yes # Lucky!
fi
+ echo \t
+ grep t
# Try the workarounds.
# Respawn using $CONFIG_SHELL if that is set and works.
if test -z "$have_echo" \
   && test "X$1" != "X--no-reexec" \
   && test -n "$CONFIG_SHELL" \
   && test -f "$CONFIG_SHELL" \
   && $CONFIG_SHELL -c "echo '\\t' | grep t > /dev/null"; then
  exec $CONFIG_SHELL "$0" --no-reexec "$@"
  exit 127
fi
+ test -z
+ test X--help != X--no-reexec
+ test -n
# For bash >= 2.04: unset the shell option xpg_echo.
if test -z "$have_echo" \
   && test -n "$BASH_VERSION" \
   && (shopt -o xpg_echo; echo '\t' | grep t > /dev/null) 2>/dev/null; then
  shopt -o xpg_echo
  have_echo=yes
fi
+ test -z
+ test -n
# 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. # (There is no win in using 'printf' over 'cat' if it is not a shell built-in.)
# Also handle problem 2, specific to bash 3.2, here.
if { test -z "$have_echo" \
     || case "$BASH_VERSION" in 3.2*) true;; *) false;; esac; \
   } \
   && test -n "$BASH_VERSION"; then \
  if type printf 2>/dev/null | grep / > /dev/null; then
    # 'printf' is not a shell built-in.
echo ()
{
cat <<EOF
$*
EOF
}
  else
    # 'printf' is a shell built-in.
echo ()
{
  printf '%s\n' "$*"
}
  fi
  if echo '\t' | grep t > /dev/null; then
    have_echo=yes
  fi
fi
+ test -z
+ test -n
# For zsh: turn sh-emulation on.
if test -z "$have_echo" \
   && test -n "$ZSH_VERSION" \
   && (emulate sh) >/dev/null 2>&1; then
  emulate sh
fi
+ test -z
+ test -n
# 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
+ test -z
if test -z "$have_echo" \
   && echo '\t' | grep t > /dev/null; then
  have_echo=yes
fi
+ test -z
+ echo \t
+ grep t
# 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. # Therefore, for an alias to take effect, the alias definition command has
#    to be executed before the command which references the alias is read."
# Because of this, we have to play strange tricks with have_echo, to ensure
# that the top-level statement containing the test starts after the 'alias'
# command.
if test -z "$have_echo"; then
bsd_echo ()
{
cat <<EOF
$*
EOF
}
alias echo=bsd_echo 2>/dev/null
fi
+ test -z
+ alias echo=bsd_echo
alias: Not found
if test -z "$have_echo" \
   && echo '\t' | grep t > /dev/null; then
  have_echo=yes
fi
+ test -z
+ echo \t
+ grep t
if test -z "$have_echo"; then
  unalias echo 2>/dev/null
fi
+ test -z
+ unalias echo
unalias: Not found
# For Solaris /bin/sh and OSF/1 /bin/sh: respawn using /bin/ksh.
if test -z "$have_echo" \
   && test "X$1" != "X--no-reexec" \
   && test -f /bin/ksh; then
  exec /bin/ksh "$0" --no-reexec "$@"
  exit 127
fi
+ test -z
+ test X--help != X--no-reexec
+ test -f /bin/ksh
+ exec /bin/ksh ./gnulib-tool --no-reexec --help

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]