2

I am interested in knowing if there is a best practice for placing/storing custom shell (Bash/Zsh) scripts and it's related PATH location.

I know folks have their favorite places - I usually dumped mine in /opt/local/bin but that required root permissions (sudo) and it was "intermixed" with all the stuff from MacPorts; thus it was unorganized to say the least. So, this is not what I'm looking for - an opinion of what each individual liked best.

Is there a generally accepted recommendation of a location/methodology to store custom scripts both system wide (all users) for individual users' own personal scripts (maybe in their home directory?) and if necessary (and available), how to structure the PATH?

9
  • Would you mind if we close this as a duplicate of apple.stackexchange.com/questions/98619/… ? – nohillside Jul 17 '20 at 8:56
  • @nohillside your answer there needs zsh added to answer this and also see my new comment – mmmmmm Jul 17 '20 at 9:01
  • 1
    And seriously...why the down vote? If you have an issue with the question - articulate it. – Allan Jul 17 '20 at 16:18
  • 2
    Don’t sweat the down vote, I highly doubt it’s any of us that commented, but even so others will find this useful over time and vote on it expect - if it’s -3 or more net, then we can worry about what’s wrong IMO. – bmike Jul 17 '20 at 19:59
  • 1
    This seems like a good question as I continue learning to be a sysadmin - it only makes sense that there is a logical place to put custom scripts and another for individual users scripts. – Doug Masters Jul 19 '20 at 16:53
2

Put things in /usr/local is the best practice for global use

Your individual user needing a separate playground / path / space is more tricky to solve.

  • How many users?
  • Where do they come from in terms of access / authentication?

Best practice (a.k.a workable and optimal) is not the same for three people that ssh in to a machine or you have thousands of students, faculty that leverage a mature file sharing / network home folder architecture or you all are developers and will check your code into source control and access many machines and want to sync things.

There’s likely no best practice than knowing your users, their skill level and preferred tools and working with your support budget. Things a professional IT team / dev team will engineer, provide and support will be far more powerful than a couple people sharing a Mac mini at the office. Those same tools are overkill for a small group or one person setting up several accounts.

Depending on your volume of items subdirectories in the local user folder can be very helpful. The only other suggestion I’ve seen that’s worth considering is /Library or ~/Library but those are further from the unix/shell heritage for my tastes.

3
  • 1
    Whatever issues this question might have, I can confirm that I have looked for a similar answer through the years, and have not found anything that would be considered a consensus that is better than /usr/local/. Even there you might find people who disagree, but it's not because they have a better idea, it's because they don't like this one. Personally, I've gone with /usr/local/scripts/ just so I can separate my items from Homebrew, etc, but that's not a consensus, just one person's practice. – TJ Luoma Jul 17 '20 at 13:30
  • 1
    @TJLuoma brew does something similar: put aliases in /usr/local but keep the scripts in Cellar. Seems like a clean and non-destructive way to do the install/ uninstall things. – anki Jul 19 '20 at 17:10
  • @ankii Yup, and I understand that model, but I found it easier to just put /usr/local/scripts/ into my $PATH. – TJ Luoma Jul 19 '20 at 22:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .