Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: #!/path/to/arch-indep/zsh -f



On Sep 22,  9:39am, Clint Olsen wrote:
} Subject: Re: #!/path/to/arch-indep/zsh -f
}
} On this crappy system (AIX 4.1.X), it must be the multiple level of
} indirection problem that Bart mentioned.  [...]  Bummer...  Compiling
} a wrapper program again defeats the purpose of having an
} architecture-independent launch point.

Two remarks:

(1) This is what autoloadable shell functions are for.  If an already-
running zsh loads and executes the function, it can't possibly be the
wrong architecture.

(2) What you're really asking for is not an arch-indep launch point, but
an arch-dependent path to the shell.  You can still have that, you just
have to do your launching a slightly different way.

Here's what you do:  Take your launcher script and fix it to pass along
a modified $0 file name to zsh, like so:

#!/bin/sh

if [ -x $OTOOLS/bin/$OS/zsh ]; then
  exec $OTOOLS/bin/$OS/zsh "$0".real "$@"
else
  exec /usr/intel/bin/zsh "$0".real "$@"
fi

(Remember, you're in sh, not zsh, so $* does word-splitting; use "$@".  If
you're really paranoid, use ${1+"$@"} [some old sh turn "$@" into an empty
string if there are no arguments at all, rather than into nothing].)

Put that in ~/bin (or wherever your scripts are) and call it "launch-zsh"
or some such.

Now, for every script that you want to be able to launch this way, run

    mv $script $script.real && ln $script launch-zsh

If you don't like the ".real" extension on every file name, put the real
script in some other directory and do a more complicated replacement on
$0 in the launcher.

It's not as clean as what you originally thought of, but it'll work.  You
can even get as clever as you like with the launcher:

#!/bin/sh

ZERO=$0.real

if [ -f $ZERO ]; then
  read scratch command switches < "$ZERO"
  case "$scratch" in
  '#!') ;;
  '#!*') switches="$command"; command="$scratch";;
  *) echo 1>&2 "$0": warning: no '#!' line in "$ZERO";;
  esac
  case "$command" in
  */zsh)
    if [ -x $OTOOLS/bin/$OS/zsh ]; then
      exec $OTOOLS/bin/$OS/zsh "$switches" "$ZERO" "$@"
    else
      exec /usr/intel/bin/zsh "$switches" "$ZERO" "$@"
    fi;;
  *) echo 1>&2 "$0": "$command" is not zsh; exit 1;;
  esac
else
  echo 1>&2 "$0": launcher found no real script
  exit 1
fi

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author