On 12/11/07, Thorsten Scherler <[EMAIL PROTECTED]> wrote:
> On Thu, 2007-11-29 at 12:08 +0000, [EMAIL PROTECTED] wrote:
> > Author: solprovider
> > Date: Thu Nov 29 04:08:11 2007
> > New Revision: 599401
> >
> > URL: http://svn.apache.org/viewvc?rev=599401&view=rev
> > Log:
> > Fixed Bug 43748.  Replaced bash-specific code with POSIX sh acceptable code.
> >
> > Modified:
> >     lenya/branches/BRANCH_1_2_X/lenya.sh
> > URL: 
> > http://svn.apache.org/viewvc/lenya/branches/BRANCH_1_2_X/lenya.sh?rev=599401&r1=599400&r2=599401&view=diff
> >
> > +++ lenya/branches/BRANCH_1_2_X/lenya.sh Thu Nov 29 04:08:11 2007
> >  # Set Lenya home to directory containing this script
> > +LENYA_HOME=${0%/*}
>
> Can you explain this change?
>
> If I open a shell and type
> echo ${0%/*}
>
> I get
> bash
>
> I do not understand.
>
> salu2
> >  cd $LENYA_HOME
> >  LENYA_HOME=`pwd -P`
> Thorsten Scherler                                 thorsten.at.apache.org

The goal of my revision to lenya.sh is to make LENYA_HOME independent
of an environment variable.  Before this change, running any of these
files:
   /lenya-1.2.2/lenya.sh
   /lenya-1.2.5/lenya.sh
   /lenya-1.2.x/lenya.sh
will start the same instance of Lenya because the environment variable
overrides the path of the command.  This is not intuitive.  When I run
/lenya-1.2.5/lenya.sh, I expect to launch Lenya 1.2.5, not Lenya
1.2.2.  More critical, running multiple instances of Lenya is not
possible when the launch command always reverts to a single instance.
Editing the lenya.sh of each instance to hardcode the directory
violates every rule of computing.

In ash, bash, csh, ksh, and every shell except the original 1977 sh,
${0%/*}
will remove the last slash and anything after the last slash from the command.

echo $0
returns
-bash
because echo is integral to bash so the "command" is bash.  Test using
the following script.

FILE: test.sh
#!/bin/sh
echo "PWD= `pwd`"
LENYA_HOME=${0%/*}
echo "LH1=$LENYA_HOME"
cd $LENYA_HOME
LENYA_HOME=`pwd -P`
echo "LH2=$LENYA_HOME"

Using people.apache.org:
/x1$ home/solprovider/test.sh
PWD= /x1
LH1=home/solprovider
LH2=/x1/home/solprovider

In English,
1. Get the path used to reach the current executable.
2. Change directory using the result of #1.  This is relative to the
current directory.  The current directory (PWD) is the directory from
which the command is called.
3. Get the absolute current path.  This removes dots and symbolic links.

This code works on every *nix except SunOS.  SunOS uses the original
1977 shell, which did not have good string manipulation.  sh and awk
were the two required programs for Unix.    String manipulation
required using awk.

I am ready to rewrite this to use awk to work on SunOS.  I am waiting
for access to zones so I can test the code.  I dislike guessing what
might work and submitting code hoping not to break anything.

Suggestions welcome.

solprovider

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to