LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 559|回复: 1

请教emerge时遇到的一个shell语法错误[已解决]

[复制链接]
发表于 2010-4-5 14:14:17 | 显示全部楼层 |阅读模式
今天emerge sudo时遇到一个奇怪的shell语法错误
USE flag参考
  1. miqiur@miahiu ~ $ emerge -pv sudo

  2. These are the packages that would be merged, in order:

  3. Calculating dependencies... done!
  4. [ebuild   R   ] app-admin/sudo-1.7.2_p4  USE="ldap pam -offensive (-selinux) -skey" 0 kB

  5. Total: 1 package (1 reinstall), Size of downloads: 0 kB
复制代码
实际运行时输出一行错误提示
  1. ./configure: line 21855: test: =: unary operator expected
复制代码
这是在configure时报的错,但错误被忽略了,emerge成功。完了之后我找到源码包/usr/portage/distfiles/sudo-1.7.2p4.tar.gz,cp到~/tmp下解压,并且确定emerge时没有添加patch。于是我找到configure源文件的第21855行
  1. if test ${with_skey-'no'} = "yes"; then
复制代码
如果条件成立会执行后面跟着的50多行代码

  1. if test ${with_AFS-'no'} = "yes"; then

  2.     # looks like the "standard" place for AFS libs is /usr/afsws/lib
  3.     AFSLIBDIRS="/usr/lib/afs /usr/afsws/lib /usr/afsws/lib/afs"
  4.     for i in $AFSLIBDIRS; do
  5.         if test -d ${i}; then

  6.     if test X"$with_rpath" = X"yes"; then
  7.         SUDO_LDFLAGS="${SUDO_LDFLAGS} -L$i -R$i"
  8.     else
  9.         SUDO_LDFLAGS="${SUDO_LDFLAGS} -L$i"
  10.     fi
  11.     if test X"$blibpath" != X"" -a "SUDO_LDFLAGS" = "SUDO_LDFLAGS"; then
  12.         blibpath_add="${blibpath_add}:$i"
  13.     fi

  14.             FOUND_AFSLIBDIR=true
  15.         fi
  16.     done
  17.     if test -z "$FOUND_AFSLIBDIR"; then
  18.         { echo "$as_me:$LINENO: WARNING: Unable to locate AFS libraries, you will have to edit the Makefile and add -L/path/to/afs/libs to SUDO_LDFLAGS or rerun configure with the --with-libpath options." >&5
  19. echo "$as_me: WARNING: Unable to locate AFS libraries, you will have to edit the Makefile and add -L/path/to/afs/libs to SUDO_LDFLAGS or rerun configure with the --with-libpath options." >&2;}
  20.     fi

  21.     # Order is important here.  Note that we build AFS_LIBS from right to left
  22.     # since AFS_LIBS may be initialized with BSD compat libs that must go last
  23.     AFS_LIBS="-laudit ${AFS_LIBS}"
  24.     for i in $AFSLIBDIRS; do
  25.         if test -f ${i}/util.a; then
  26.             AFS_LIBS="${i}/util.a ${AFS_LIBS}"
  27.             FOUND_UTIL_A=true
  28.             break;
  29.         fi
  30.     done
  31.     if test -z "$FOUND_UTIL_A"; then
  32.         AFS_LIBS="-lutil ${AFS_LIBS}"
  33.     fi
  34.     AFS_LIBS="-lkauth -lprot -lubik -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err ${AFS_LIBS}"

  35.     # AFS includes may live in /usr/include on some machines...
  36.     for i in /usr/afsws/include; do
  37.         if test -d ${i}; then
  38.             CPPFLAGS="${CPPFLAGS} -I${i}"
  39.             FOUND_AFSINCDIR=true
  40.         fi
  41.     done

  42.     if test -z "$FOUND_AFSLIBDIR"; then
  43.         { echo "$as_me:$LINENO: WARNING: Unable to locate AFS include dir, you may have to edit the Makefile and add -I/path/to/afs/includes to CPPFLAGS or rerun configure with the --with-incpath options." >&5
  44. echo "$as_me: WARNING: Unable to locate AFS include dir, you may have to edit the Makefile and add -I/path/to/afs/includes to CPPFLAGS or rerun configure with the --with-incpath options." >&2;}
  45.     fi

  46.     AUTH_OBJS="$AUTH_OBJS afs.o"
  47. fi

复制代码
但因为这个错误,导致这些代码都没有执行。
但我发现这个错误很奇怪,在交互式bash和交互式sh环境下都无法重现,要想出现这个错误必须是这种形式的代码
  1. miqiur@miahiu ~/tmp $ test = "yes"
  2. -bash: test: =: unary operator expectedtest
复制代码
也就是说configure脚本中的
  1. test ${with_skey-'no'} = "yes"
复制代码
被解释成
  1. test = "yes"
复制代码
但是无论在bash里还是在sh里,不管with_skey变量是否初始化,长度是否为0,${with_skey-'no'}都会被赋值为一个非空非零长的值。
所以我对这个错误一直无法理解。
请教各位,这是为何。
是否和shell的设置有关?
附上configure脚本的前30行,包含一些shell的设置,脚本的其它地方也有,但没细看,太长了
  1. miqiur@miahiu ~/tmp/sudo/sudo-1.7.2p4 $ head -30 configure
  2. #! /bin/sh
  3. # Guess values for system-dependent variables and create Makefiles.
  4. # Generated by GNU Autoconf 2.61 for sudo 1.7.2p4.
  5. #
  6. # Report bugs to <http://www.sudo.ws/bugs/>.
  7. #
  8. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
  9. # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
  10. # This configure script is free software; the Free Software Foundation
  11. # gives unlimited permission to copy, distribute and modify it.
  12. ## --------------------- ##
  13. ## M4sh Initialization.  ##
  14. ## --------------------- ##

  15. # Be more Bourne compatible
  16. DUALCASE=1; export DUALCASE # for MKS sh
  17. if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
  18.   emulate sh
  19.   NULLCMD=:
  20.   # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
  21.   # is contrary to our usage.  Disable this feature.
  22.   alias -g '${1+"$@"}'='"$@"'
  23.   setopt NO_GLOB_SUBST
  24. else
  25.   case `(set -o) 2>/dev/null` in
  26.   *posix*) set -o posix ;;
  27. esac

  28. fi

复制代码

我系统上的/bin/sh是链接到bash的
  1. miqiur@miahiu ~/tmp/sudo/sudo-1.7.2p4 $ readlink -f /bin/sh
  2. /bin/bash
复制代码
 楼主| 发表于 2010-4-5 14:43:01 | 显示全部楼层
不好意思,解决了
  1. sh-4.0$ zerolength=
  2. sh-4.0$ test ${zerolength-no} = "yes"
  3. sh: test: =: unary operator expected
  4. sh-4.0$ test ${zerolength-:no} = "yes"
  5. sh: test: =: unary operator expected
  6. sh-4.0$ echo ${zerolength-no}

  7. sh-4.0$ echo ${zerolength:-no}
  8. no
  9. sh-4.0$ unset zerolength
  10. sh-4.0$ test ${zerolength-no} = "yes"
  11. sh-4.0$ test ${zerolength-:no} = "yes"
  12. sh-4.0$ echo ${zerolength-no}
  13. no
  14. sh-4.0$ echo ${zerolength:-no}
  15. no
  16. sh-4.0$ zerolength=xxxxx
  17. sh-4.0$ test ${zerolength-no} = "yes"
  18. sh-4.0$ test ${zerolength-:no} = "yes"
  19. sh-4.0$ echo ${zerolength-no}
  20. xxxxx
  21. sh-4.0$ echo ${zerolength:-no}
  22. xxxxx
  23. sh-4.0$ zerolength=
  24. sh-4.0$ test "${zerolength-no}" = "yes"
  25. sh-4.0$ test "${zerolength-:no}" = "yes"
  26. sh-4.0$ echo "${zerolength-no}"

  27. sh-4.0$ echo "${zerolength:-no}"
  28. no
复制代码
得加上双引号才能避免这种错误
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表