In ubuntu scripts can be executed with following commands:
$ chmod +x manage.py
$ manage.py
However in mac you need to use ./ in order to actually run the script, as follow:
$ chmod +x manage.py
$ ./manage.py
I would like to know what is exactly ./ (especially that both system use bash by default) and if there is a way to run scripts directly in mac?
It's because you (very sensibly) don't have
.
in yourPATH
environment variable. If you do, it becomes an attack vector for people to get you to execute their own code instead of real stuff.For example, let's say your path is:
so that commands will first be searched for in your current directory, then in
/usr/bin
.Then another user creates an executable script file
ls
in their home directory which changes to your home directory and deletes all your files. Then they tell you they've got something interesting in their home directory. You runls
to see what they have, and your files are deleted. All because it ranls
from your current directory first.This is a particular favorite attack vector against naive system admins.
To be honest, on my home machines, I don't worry too much, since I'm the only user and I'm not prone to downloading stuff I don't trust. So I usually add
.
to my path for convenience, but usually at the end so it doesn't get in the way of my more regular commands.When you are executing a command that file (script/binary) needs to be found by the system. That is done by putting directories where to look for scripts into the PATH environment variable. So if it works in ubuntu it means PATH includes '.' (the current directory). If you want the same behavior on mac then put something like export PATH="$PATH:." in your .bashrc (asuming you are using bash..)