Why do we use ./ (dot slash) to run Linux scripts?
The Unix ./ script syntax can be explained in three parts:
The role of the application PATH in Linux
The ./ notation denotes the current directory
The need to avoid conflicts with existing commands
Unix’s dot slash vs the PATH
Every computer has an application PATH. This is a collection of directories in which the OS looks when an executable command or runnable script is invoked.
All of the built-in commands you are familiar with, such as ls, cat, echo, touch, and chmod, are on the application PATH. Users often put the commonly used programs in the JDK or Git on the application PATH as well.
The problem is, if you’re trying to invoke a script you wrote yourself, it’s likely not saved in a folder that’s part of the application PATH. This means if you run your custom script like you would a command that resides on the PATH, the Linux OS won’t find it.
Meaning of ./ in Linux
This is where the dot slash ./ notation comes in. It means “Look in the current directory.” When you use ./, you tell Ubuntu or Fedora or SUSE or whatever Linux distribution you’re using to look in the current directory for the command you wish to run, and completely ignore what’s on the application PAT
#!
-script there. (And the fact that the binary looks even less like a shell script so the shells croak faster.) – ilkkachu Jul 06 '22 at 14:40