emulate sh

PostgreSQL的configure 脚本中有如下代码:

if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else
  case `(set -o) 2>/dev/null` in  *posix*) set -o posix ;;
  esac

fi

之前已经验证过,如果系统当前shell为 zsh, 则执行 emulate sh 命令。

那么 emulate sh 到底是干什么的呢?可以参见下列的解释:

http://www.acm.uiuc.edu/workshops/zsh/emulation.html

Zsh can emulate sh, ksh, or csh. (csh is not fully emulated). zsh does an outstanding job in its sh and ksh emulation.

You can start emulating another shell by running emulate some_shell from the command line. If you add the -R flag, all options will be reset to their default values.

You can also create a link called 'csh', or 'ksh', or 'sh' that points to zsh. Zsh will notice that it was invoked with a different name, and do its best to behave like the shell you specify.

原文地址:https://www.cnblogs.com/gaojian/p/2598846.html