1

I was directed here from Stack Overflow after posting a question about struggling to get PyExifTool to work. It seems however that the problem was multifaceted and being a novice I was told to seek help here.

Essentially the problem was realised when I was told to run...

bash:~ $ type -all exiftool

which returned...

exiftool is /usr/local/bin/exiftool
exiftool is /usr/local/bin/exiftool

...revealing that somewhere I had duplicates.

Subsequently, I ran...

bash:~ $ echo $PATH

Which returned...

/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/fsl/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin~/.bash_profile

...which contains duplicates and apparently should not end with .bash_profile

Now in the terminal, I can clean this up using...

bash:~ $ PATH=$(echo $PATH | awk -v RS=: -v ORS=: '!($0 in a) {a[$0]; print}')

The above is a snippet that I got from Linux Journal that is supposed to 'nearly work' but the piece of code that 'should work' doesn't seem to help me. Using the 'nearly functional' code gives the following:

/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/fsl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin~/.bash_profile :

I'm an utter novice but I don't think it's supposed to end in : and clearly the .bash_profile is still present. However, it does seem to remove duplicates, though this resets if I open a new terminal window so it's only an acute workaround.

This is what my bash profile looks like:

export PATH=/usr/local/bin:$PATH~/.bash_profile

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
#PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
#export PATH

# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
#PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
#export PATH


# FSL Setup
FSLDIR=/usr/local/fsl
PATH=${FSLDIR}/bin:${PATH}
export FSLDIR PATH
. ${FSLDIR}/etc/fslconf/fsl.sh


# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH

I'm not sure if this is relevant or related but when I launch python from my Hotbar and run...

>>> print(os.environ['PATH'])

It prints

/usr/bin:/bin:/usr/sbin:/sbin

Whereas when I launch it from my bash terminal using IDLE3 it returns:

/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/fsl/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin~/.bash_profile

Peripheral Information & Experimentation:

I think I probably messed something up when installing FSL, did something to my .bash_profile and am now being haunted while trying to learn and develop basic coding skills. Maybe it was a manual error or perhaps it had something to do with homebrew or Xcode.

I could delete the .bash_profile ending but I am concerned I have already done enough damage and don't want to troubleshoot myself into a problem so laborious no internet forum wants to touch it.

This is what was supposed to work according to Mitch Frazier from Linux Journal. Obviously this is no reflection on him or the article but rather on my limited understanding.

bash:~ $ export PATH=/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/fsl/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin~/.bash_profile
bash:~ $ echo -n $PATH | awk -v RS=: '!($0 in a) {a[$0]; printf("%s%s", length(a) > 1 ? ":" : "", $0)}'

This returns...

/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/fsl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin~/.bash_profileUser's-MBP:~ username$

I have also tried the following (suggested by pepa65)...

bash:~ $ PATH=$(n= IFS=':'; for e in $PATH; do [[ :$n == *:$e:* ]] || n+=$e:; done; echo "${n:0: -1}")

This returns...

-bash:  -1: substring expression < 0

When I try to look for changes using echo $PATH...

I get a blank line.

I know this is unlikely to be intellectually stimulating so I am grateful for any help.

EDIT 1:

A naive attempt to remove .bash_profile from the end of the first line of my .bash_profile did not make it disappear from the output of echo $PATH which remained unchanged.

1 Answer 1

0

Here is a reduced and corrected .bash_profile which is hopelully adequate for your configuration.

There was a problematic line at the beginning where ~/.bash_profile had erroneusly been added to an otherwise correct line. However, I removed the whole line, since I would expect, and your diagnostics suggest, that it was adding a directory which was already on the system-supplied default PATH.

There is definitely no need to export PATH more than once; probably you could safely remove even the one remaining instance. The meaning of export is to mark a variable to be made into an environment variable which is visible to subprocesses. Once you have done that, subprocesses will have access to the current value of the variable, even if the value changes after the export. Quite probably your system-wide shell configuration already does this for the PATH variable (otherwise it could not work as intended).

I removed entire sections which were commented out; you might of course want to bring them back and uncomment them.

# FSL Setup
FSLDIR=/usr/local/fsl
PATH=${FSLDIR}/bin:${PATH}
export FSLDIR PATH
. ${FSLDIR}/etc/fslconf/fsl.sh

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"

This file is read when you start up a new shell, though when exactly will also depend on how your OS vendor has configured Bash. To be completely sure that any old configuration is no longer interfering with your current configuration, you will have to figure out whether logging out and back in is required to start over, or if you can simply start a new shell or a new terminal session to get a clean slate.

Perhaps still review whether .bash_profile.pysave contains something useful you want to keep, though I would expect it to be by and large identical to your current version, except for the very last set of lines.

2
  • This is a really helpful answer, particularly as I better understand what my profile is up to now. I would just like to enquire as to whether I can coax my Hotbar IDLE to work as well as the one I launch from prompt using IDLE3 or is this best saved for a separate question? I think you have gone above and beyond already so please don't fret if it's a question for a different time. Commented Aug 16, 2020 at 14:43
  • Definitely a separate topic; probably see apple.stackexchange.com/questions/51677/… Commented Aug 16, 2020 at 16:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.