Re: PATH and $0

2006-07-13 Thread Bob Proulx
Stephane Chazelas wrote:
> $0 will always  contain the file path, unless the script was
> started as:
>
> bash script.sh
>
> And there's no script.sh in the current directory (in which case
> sh/bash will have looked up script.sh in $PATH).

Of course using command as you have done will work for bash.  But I
always feel better about using portable shell as much as possible.
here is one way.

  pathfind() {
OLDIFS="$IFS"
IFS=:
for p in $PATH; do
  if [ -x "$p/$*" ]; then
IFS="$OLDIFS"
echo "$p/$*"
  fi
done
IFS="$OLDIFS"
  }

> #! /bin/sh -
> dir=$(
>   cmd=$0
>   [ -e "$cmd" ] || cmd=$(command -v -- "$cmd") || exit
>   dir=$(dirname -- "$cmd")
>   cd -P -- "$dir" && pwd -P
> ) || exit
> # untested
>
> should give you the absolute path of the directory portion of
> the script path (unless that directory ends in newline
> characters).

One thing to note about this script is that it canonicalizes path with
respect to symlinks.  You do say that but without much fanfare.  It
raises a red flag for me.  I think that canonicalizing the path is
doing too much.  You did say untested and I acknowledge the caveats
you were trying to warn about.

Here is a problem.  Let's say a binary lives on an automounted
partition such as the old BSD amd.  PATH can point to the trigger
directory (e.g. /net/foo) and so searching there will trigger a mount
operation.  The actual location may be /.automount/net/foo with a
symlink to it and that is the path that will be returned by the above.
Enough time might passes that amd unmounts the directory.  Now when
access to $0 or the directory above is attempted in the future with
that path it will fail because the directory is not mounted and not
going through the trigger directory it won't be mounted.  This is
unexpected to the user.

I think it is best to accept whatever path the user has provided
verbatim.  I would not try to canonicalize the path in any way.  If
the user has provided a path with /foo/bar/../../zoo/zam for example
then I would just go with it because that path may actually be
necessary just like that for some reason as yet unknown at this moment
to us writing the code to be used in the future.  The reason I think
this way is that I have tried to do things like canonicalizing
previously myself and gotten burned by it.  I have learned it is
better to avoid doing such things.

Bob


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: bash 3.1 on Solaris 9

2006-07-13 Thread Bob Proulx
Cheltenham, Christopher J wrote:
> What can I do for this error?
> 
> ld.so.1: bash: fatal: libiconv.so.2: open failed: No such file or
> directory
> Killed

You apparently got a precompiled binary from some third party.  That
binary is using a shared library that it did not include.  Probably at
the same place that you got the bash binary you would also find the
libiconv shared library.  Install it too.  Repeat as needed.

Or you could pull the source code to bash and compile it yourself
which would build it without that dependency.  The GNU project
generally distributes source code.  A whole infrastructure of third
parties have developed around compiling the source code and
distributing it.  But really anyone can compile the code and this is
encouraged.

Bob


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: bash 3.1 on Solaris 9

2006-07-13 Thread Mike Frysinger
On Thursday 13 July 2006 14:06, Cheltenham, Christopher J wrote:
> What can I do for this error?

not that this has anything to do with bash, but you could try installing the 
library bash is complaining about:

> ld.so.1: bash: fatal: libiconv.so.2: open failed: No such file or
> directory
-mike


pgp5At37eaPkq.pgp
Description: PGP signature
___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


bash 3.1 on Solaris 9

2006-07-13 Thread Cheltenham, Christopher J
What can I do for this error?


ld.so.1: bash: fatal: libiconv.so.2: open failed: No such file or
directory
Killed


Thanks a bunch

=
Chris Cheltenham  
Computer Specialist
Campbell Library @ Rowan University  
Glassboro, NJ 
856-256-4979   
=

___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash