0

I often use the env utility in the shebang to call python2 because the location of python2 is not always the same accross systems :

/usr/local/bin/python2
/usr/bin/python2

Therefore, here is my the shebang line I use :

#!/usr/bin/env python2

My pb. is that the DYLD_LIBRARY_PATH variable gets ignored or reset by the env utility on Macos :

I have the following line in my .profile :

export DYLD_LIBRARY_PATH=$HOME/local/lib
export DUMMY=$HOME/local/lib

Let testENV.sh the following shell script :

#!/usr/bin/env bash

test $(uname -s) = Linux  && echo "=> LD_LIBRARY_PATH   = $LD_LIBRARY_PATH"
test $(uname -s) = Darwin && echo "=> DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH"

echo "=> DUMMY = $DUMMY"

If I run ./testENV.sh on LINUX, the result is :

=> LD_LIBRARY_PATH = /users/EtuX/0123456789/local/lib
=> DUMMY = /users/EtuX/0123456789/local/lib

If I run ./testENV.sh on Macos, the result is :

=> DYLD_LIBRARY_PATH =
=> DUMMY = /Users/xyztxyzt/local/lib

If I print the DYLD_LIBRARY_PATH variable using echo from outside the script (at the bash prompt), it shows :

/Users/xyztxyzt/local/lib

INFO : My .profile is a symbolic link to .bash_profile

EDIT 2 : On Macos, the env utility seems to be the "guilty" one :

$ which env
/usr/bin/env
$ env bash testENV.sh
=> DYLD_LIBRARY_PATH =
=> DUMMY = /Users/xyztxyzt/local/lib
$ bash testENV.sh
=> DYLD_LIBRARY_PATH = /Users/xyztxyzt/local/lib
=> DUMMY = /Users/xyztxyzt/local/lib

EDIT 3 : Replaced LD_LIBRARY_PATH by DYLD_LIBRARY_PATH

EDIT 4 : Updated the testENV.sh shell script.

EDIT 5 : Updated the testENV.sh shell script with the DUMMY variable.

Is there a way to make it work ?

SebMa
  • 4,037
  • 29
  • 39
  • 3
    `.profile` is loaded by the login shell, probably not the newly created environment of the subprocess – OneCricketeer Aug 28 '17 at 10:13
  • Does it work if you export the `LD_LIBRARY_PATH` from the shell you are using to run the script? – Hubert Grzeskowiak Aug 28 '17 at 10:15
  • Shouldn't you use `DYLD_LIBRARY_PATH`? – CristiFati Aug 28 '17 at 10:15
  • @CristiFati You are right on the name of this variable, but this pb. occurs with any exported variable on Macos – SebMa Aug 28 '17 at 11:53
  • @HubertGrzeskowiak If I echo the variable from outside the script, it show the content of the variable, this means the variable is already exported – SebMa Aug 28 '17 at 11:54
  • Does _bash_ use _.profile_? It has its own set of files (at least on some *OS*es): _.bashrc_ and _.bash\_profile_. You should `echo` something from _.profile_ and see whether it gets printed out when executing your script. – CristiFati Aug 28 '17 at 12:33
  • @CristiFati My `.profile` is a symbolic link to `.bash_profile` – SebMa Aug 28 '17 at 12:44
  • 1
    Test with a different environment variable (PATH for example). I suspect Mac does some funny things with DYLD_LIBRARY_PATH. No; I don't have clear explanation. It seems, roughly, that a given shell can set DYLD_LIBRARY_PATH, but it is reset to empty when a new shell is started. (I can reproduce the problem using your script on my Mac.) – Jonathan Leffler Aug 28 '17 at 15:46
  • @JonathanLeffler I guess you are right. Updating the question with another variable – SebMa Aug 28 '17 at 16:39

0 Answers0