[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problem Running Application with Alias



Petter Adsen wrote:
> On Sat, 23 May 2015 09:36:31 -0400
> > LD_LIBRARY_PATH="/opt/mopac/MOPAC2012.exe:$LD_LIBRARY_PATH"
> 
> This is an obvious thing that jumps out at me, this line should be:
> 
> LD_LIBRARY_PATH="/opt/mopac:$LD_LIBRARY_PATH"
> 
> as LD_LIBRARY_PATH is meant to contain directories where shared
> libraries can be found, not an executable binary.

I have a small comment concerning the syntax.  I am sure you are
correct about the problem.  But both of those assume that
$LD_LIBRARY_PATH already exists in the environment.  If it does then
fine.  Let me use "foo" as a stand-in for the explanation.

  $ foo=/bar
  $ foo=/opt/somepath:$foo
  $ echo "$foo"
  /opt/somepath:/bar

But if it does not exist then it leaves the environment variable with
a hanging colon at the end.

  $ unset foo
  $ foo=/opt/somepath:$foo
  $ echo "$foo"
  /opt/somepath:

That is bad and actually has been argued is a security consideration
in other paths such as PATH.

To avoid that the following shell syntax is typically used.

  $ foo="/bar"
  $ foo=/opt/somepath${foo+:$foo}
  $ echo "$foo"
  /opt/somepath:/bar

  $ unset foo
  $ foo=/opt/somepath${foo+:$foo}
  $ echo "$foo"
  /opt/somepath

Or to append to the end of the path put the colon on the other side.

  $ foo="/bar"
  $ foo=${foo+$foo:}/opt/somepath
  $ echo "$foo"
  /bar:/opt/somepath

  $ unset foo
  $ foo=${foo+$foo:}/opt/somepath
  $ echo "$foo"
  /opt/somepath

The dash documentation on this standard shell feature is:

     ${parameter:+word}    Use Alternative Value.  If parameter is unset or
                           null, null is substituted; otherwise, the expansion
                           of word is substituted.

     In the parameter expansions shown previously, use of the colon in the
     format results in a test for a parameter that is unset or null; omission
     of the colon results in a test for a parameter that is only unset.

The form without the colon is correct for path handling so that it
maintains the state in the case that the variable was already set to
an empty value indicating the current working directory.

  $ foo=""
  $ foo=${foo+$foo:}/opt/somepath
  $ echo "$foo"
  :/opt/somepath

Note however that an empty path indicating using the current working
directory is almost never desirable.  In the case of LD_LIBRARY_PATH
one would never want to have it set to an empty value.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: