Bash scripting

At exercise https://www.codecademy.com/courses/learn-the-command-line/lessons/learn-bash-scripting/exercises/introduction
written that
you must add this directory to your PATH within your configuration file:

  • PATH=~/bin:$PATH

Now any scripts in the ~/bin directory can be run from anywhere by typing the filename.
Question is
1)There is no bin directory in home(~) and it is in root (/) directory
2)Inside the bin folder I am unable to create any file it is not permitted error comes although using su

Using on MAC OSX

1 Like

depending on your linux or macOS installation, the bin directory might not yet exist. You can create it of course

that is conflicting with point 1 you made. Can you elaborate?

note that the bin directory in your home directory (~/bin) is for the current user.

1 Like
  1. bin is in root directory and not in home directory
  2. Inside root directory and inside that bin folder I cannot create any script

So did you mean to say that I create bin folder in home directory and write scripts inside it by setting the PATH

adding a bin directory to your home directory allows you to easily run scripts as current user. If the directory doesn’t exist, you should create it:

mkdir $HOME/bin

with the right privileges, you certainly can. But why would you?

Okay I got your point, But why I am unable to create a script inside the bin folder of root directory
Although I am super user and use

sudo vi new.sh

It give me error that it is read only and you cannot write when I save :wq

it seems macOS has something called SIP (system intergrity protection), which seems to be the issue you run into:

https://en.wikipedia.org/wiki/System_Integrity_Protection

i can perfectly place scripts in /bin, but looking at what bin is used for:

https://askubuntu.com/questions/308045/differences-between-bin-sbin-usr-bin-usr-sbin-usr-local-bin-usr-local

i wouldn’t.

1 Like