Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do you keep your own scripts on OSX? [closed]

As I write my bash scripts for my OS X that do general things, I am wondering where is a good place to keep them. Is there a directory I can put them all in where they will be picked up automatically? Or should I create my own directory and then reference this directory from .profile or something?

like image 266
More Than Five Avatar asked Sep 08 '13 09:09

More Than Five


People also ask

Where should I store my script files?

If any user on the system should be able to run the script, put it in /usr/local/bin . Don't put scripts you write yourself in /bin or /usr/bin . Those directories are intended for programs managed by the operating system.

Where is the script folder on Mac?

To add computer-level scripts to the script menu, save them into the /Library/Scripts/ folder on your Mac. For quick access to this folder, select Open Scripts Folder > Open Computer Scripts Folder from the script menu. When you do this, the folder is automatically created if it doesn't already exist.

How do I view scripts on Mac?

In the Script Editor app on your Mac, choose Script Editor > Preferences, then click General. Select the “Show Script menu in menu bar” checkbox, then make sure the “Show Computer scripts” checkbox is selected. The Script menu appears on the right side of the menu bar.

Where are bash scripts stored?

The "official" place for local executables is /usr/local/bin . This directory is usually in the $PATH of all users by default. Traditionally, programs that are not installed through a package manager (eg apt ) are stored in the /usr/local/bin directory and those installed by the package manager in /usr/bin .


2 Answers

Usually /usr/local/bin, unless you don't want other users to have access to them, in which case $HOME/bin.

/usr/local/bin may be in the default PATH, but $HOME/bin will certainly need to be added to PATH.


Adding $HOME/bin to PATH:
PATH=${PATH}:$HOME/bin export PATH 
like image 123
Paul R Avatar answered Sep 28 '22 01:09

Paul R


I have my PATH set as:

  • /usr/local/bin
  • /usr/bin
  • /bin
  • /usr/sbin
  • /sbin
  • $HOME/bin

I use /usr/local/bin for commands that I have that override the default commands. For example, I have Subversion 1.7.7 installed, and the OS X comes with 1.6.18. The version 1.7.7 of svn is in /usr/local/bin while the default 1.6.18 version of svn is in /usr/bin. When I type svn, I get the version I installed instead of the version that comes with OS X. I've done this with Java, Git, Python, and several other binaries where I need a different version that what came on my Mac. Most of these are symbolic links. For example:

$ ls -l /usr/local/bin/ant lrwxr-xr-x  1 root  wheel       16 Jun 12 11:01 ant -> /opt/ant/bin/ant 

Ant 1.9.1 is installed in /opt/ant (actually, /opt/apache-ant-1.9.1, but it's symbolically linked to /opt/ant). I linked all the stuff under /opt/ant/bin to /usr/local/bin, so it's in my path.

I use $HOME/bin for my personal shell scripts and other scripts. Traditionally, you make this the last entry in your PATH, so you don't accidentally override a built in command. If I made a shell script command called cp, I wouldn't override the /bin/cp command.

like image 26
David W. Avatar answered Sep 28 '22 02:09

David W.