Best Practice for User Shell Scripts location and/or PATH

bashcommand linezsh

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?

Best Answer

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.