[Xquartz-dev] 2.3.2_rc4

Cameron Simpson cs at zip.com.au
Fri Dec 26 17:47:55 PST 2008


On 26Dec2008 15:21, Jeremy Huddleston <jeremyhu at apple.com> wrote:
>> In fact, I've copied the whole case statement into my generic script,
>> which makes it more efficient in standalone use and lets you strip
>> this
>> wrapper down further, should you wish. It would let the wrapper be an
>> "if" statement, clearer in its purpose.
>
> Can you send your updated script to the list.

Attached. It reduces the wrapper to:

  #!/bin/sh
  set "$(dirname "$0")"/X11.bin "${@}"
                                                                                  if [ -x "$HOME/.x11run" ]; then
    exec "$HOME/.x11run" "${@}"
  else
    exec with-login-env "${@}"
  fi

>> A minor question: why "${@}" instead of "$@" ? And why "${SHELL}"
>> instead of "$SHELL"?
>
> Because things like $PREFIX/bin make me cry, so I like ${...}

Ok.

>> And we should put a usage message and abort at the top if there are no
>> arguments i.e. no command supplied:
>
> No... If there are no command line arguments, then we just exec X11.bin
> with no command line arguments.

Ah, I had missed this. Fine. Latest with-login-env attached. Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
-------------- next part --------------
#!/bin/bash -ue
#
# Run an arbitrary command with user user's login environment.
# Based on discussions with Martin Costabel, Peter O'Gorman,
# Harald Hanche-Olsen and Jeremy Huddleston.
# Uses bash instead of sh for "printf %q" and "exec -l".
#       - Cameron Simpson <cs at zip.com.au> 23dec2008
#

: ${SHELL:=/bin/sh}

cmd=$0
haveenv=

usage="Usage: $cmd {--have-login-env | command [args...]|"

if [ $# -gt 0 ] && [ "x$1" = x--have-login-env ]
then
  haveenv=1
  shift
fi

[ $# -gt 0 ] || set -- env

if [ $haveenv ]
then
  eval "set -- $_WITH_LOGIN_ENV_QUOTED_COMMAND"
  unset _WITH_LOGIN_ENV_QUOTED_COMMAND
  exec "$@"
fi

# direct methods for known shells
bshell=`basename "$SHELL"`
case "$bshell" in
  bash)         exec    "${SHELL}" --login -c 'exec "${@}"' - "${@}" ;;
  ksh|sh|zsh)   exec -l "${SHELL}" -c 'exec "${@}"' - "${@}" ;;
  csh|tcsh)     exec -l "${SHELL}" -c 'exec $argv:q' "${@}" ;;
  es|rc)        exec -l "${SHELL}" -c 'exec $*' "${@}" ;;
esac

# otherwise use generic method with a conservative command
case "$0" in
  *\'*) ecmd=`printf '%s\n' "$0" | sed "s/'/'\\''/g"` ;;
  *)    ecmd=$0 ;;
esac

qcmd=
for arg
do  qcmd=$qcmd`printf " %q" "$arg"`
done
_WITH_LOGIN_ENV_QUOTED_COMMAND=$qcmd
export _WITH_LOGIN_ENV_QUOTED_COMMAND
exec -l "$SHELL" -c "exec '$ecmd' --have-login-env"


More information about the Xquartz-dev mailing list