[Xquartz-dev] 2.3.2_rc4

Cameron Simpson cs at zip.com.au
Fri Dec 19 18:44:46 PST 2008


On 20Dec2008 12:44, I wrote:
| On 20Dec2008 01:37, Martin Costabel <costabel at wanadoo.fr> wrote:
| > Peter O'Gorman wrote:
| >> My question was, why not:
| >> #! /bin/bash
| >> exec -l "$SHELL" "$@"
[...errors...]
| > No explanation; just observing...
| 
| I have an explaination.

More on that: Peter ends up running, for example:

  /bin/sh ls -la

which attempts to execute  /bin/ls as shell source code. You need to use
the shell's -c option (reliable for all UNIX shells) and we're off into
quote-the-command land again.

| This skips login(1) and possibly addresses Harald's issue with = signs
| in the zeroeth argument. It doesn't address the generic syntax issue
| he raises.
| 
| I have an idea for that for my next post (have to do a machine shutdown
| first:-)

[Server halted, heat sinks vacuumed, new fan installed, reassembled, booted...]

Ok. A robust solution to this requires two scripts, let's call them
run-via-login and run-via-login-post. We do this:

run-via-login:

  #!/bin/bash
  qcmd=
  for arg
  do  qcmd=$qcmd`printf " %q" "$arg"`
  done
  export _EXPORTED_QUOTED_COMMAND=$qcmd
  exec -l "$SHELL" -c 'exec /path/to/run-via-login-post'

run-via-login-post:

  #!/bin/bash
  eval "set -- $_EXPORTED_QUOTED_COMMAND"
  unset _EXPORTED_QUOTED_COMMAND
  exec "$@"

In this scheme we pass the argument list in the environment. Because
it's being sent as a string, we quote it as before. Instead of relying
on the bash quoting working in an arbitrary shell, we just tell the
arbitrary shell to:

  exec /path/to/run-via-login-post

We can dop the "exec " if there's a shell that doesn't accept it.
run-via-login-post sets up the command line again from the exported string
(and because it's bash we know the quoting syntax matches), removes the
exported string from the environment, and execs the command line.

Comments?
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Work to eat, eat to live, live to bike, bike to work.


More information about the Xquartz-dev mailing list