0

I have a folder in my home called tools, it is where I place all the utilities I use for my projects. Each folder in tools has a /bin subdirectory that I want to add to my path. my .profile file currently has this piece of code added to it:

    # add directories to path below
if [-d "$HOME/tools"]; then
  for d in $HOME/tools/*/bin; do PATH="$PATH:$d"; done
fi

I scrapped this together from related threads on how to add folders to path, but have ended up no further than where I began. What i'd like for it to do is for each subfolder within tools, add the bin to path. Any pointers?

  • 3
    Add a shebang and then paste your script there: http://www.shellcheck.net/ – Cyrus Mar 10 '19 at 21:39
  • 2
    The problem in your script are the missing spaces around `[` and `]`. By the way: The `if [ -d` is not necessary when you use `shopt -s nullglob`. With nullglobs `for d in $HOME/tools/*/bin` will only be entered if the directory exists. – Socowi Mar 10 '19 at 21:46
  • See [Why should there be a space after '\[' and before '\]' in Bash?](https://stackoverflow.com/q/9581064/4154375). – pjh Mar 11 '19 at 14:31

1 Answers1

0

Thanks to Socowi for the info. I removed the if statement and edited for for loop a bit and its working how i intended.

for d in $HOME/tools/*; do PATH="$PATH:$d/bin"; done