0

I am a new macOS user and I want to create a bash script that I can add to the PATH and run as a "normal" command (cd for example). I'm the only user of the Mac and so I'll be forever, but just in case, I don't want to put my script in a place where other users can run it.

What's the standar way of doing so? Do i have to put it in my home directory? or maybe somewhere in the root and restrict access with chmod? I'm a bit confused... Any help is appreciated!

Essay97
  • 103
  • 3

2 Answers2

3

As the other answers have noted anything in your home directory (under $HOME) is only writeable by you by default. (and admin users). If you want to make the scripts not runnable by other users you will need to chnage the file permissions and remove the execute bit from the group and others

However the other answers do not deal with getting it to run and do not relly answer the question which I think how do I get the command into my PATH and not on others.

The usual place to put scripts only for you traditionally in unix is in a directory $HOME/bin (although newer suggestions include $HOME/.local/bin

You have to create either of those and then add them to your path

In bash and zsh this is to add export PATH=~/bin:$PATH to your startup files (~/.bashrc or ~/.zshrc) as you usually want your commands to be found before general commands.

mmmmmm
  • 30,160
  • So if you only have an admin account then everyone can read everything… – Solar Mike Feb 05 '22 at 11:23
  • Well if there is only one account there is nobody else. However admin (well sudo enabled) accounts can read any file. And I just checked umask is 022 so anyone in your group can read your files which by default is all users. So in practice on a Mac all users can read your files - in a centralised real multi user setup then network administrators will chnage this. – mmmmmm Feb 05 '22 at 11:34
1

The whole point of user accounts is to provide areas that are separate to each user.

The contents of your user account are not normally available to other users, and vice versa.

If you want to make your script only available to 'your user', then put it somewhere inside your user account.

benwiggy
  • 35,635