0

A silly question but was curious to know the significance of ./ which executing a script in a directory while outside the directory we run it by giving the full path

RJ.
  • 332
  • 5
  • 16

4 Answers4

2

./ tells the shell that the command should be run inside the current directory. If you don't have the command you are trying to run in the Path then you need to tell the shell where to look for it. If it resides in the current directory then you would use ./ otherwise providing the full path will do the same thing.

Matt Phillips
  • 11,249
  • 10
  • 46
  • 71
2

Best dot slash explanation ever.

http://www.linfo.org/dot_slash.html

c1tadel1
  • 126
  • 3
  • That explanation is incorrect. The shell doesn't check for an absolute path; it just checks for the presence of a slash (which could also be a relative path). If the first word contains a slash, searching $PATH is skipped. Try `mkdir tmp; echo '#!/bin/echo' > tmp/test && chmod +x tmp/test` and then just run `tmp/test` without the leading `./` - it will work in pretty much all current systems which have a non-stupid exec() call. And that's how `./script` works; there's a slash in it, so the $PATH is not searched. The `.` is just another directory, albeit a special one. – dannysauer May 20 '14 at 17:35
1

every shell has a PATH environment variable. The path is a list of directories where executables are located. When you type a command, the shell looks for the command in the defined path.

By default, the current directory is not on the path, so if you type the executable name it wont be found (unless there is an executable with that name on the path somewhere). The "./" signifies the current directory.

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
0

Specifying a path with a slash in it causes the shell to skip searching the $PATH. So you provide a specific path to make sure you're running the file you intend (in the event that your script name is the same as something in the $PATH). Further, you use the ./ since the current directory isn't in the $PATH - just like everyone else said. :)

dannysauer
  • 3,793
  • 1
  • 23
  • 30