What is the difference between filename and ./filename? Under what circumstances is one preferred to the other?
|
|
|
For datafiles, it does not make a difference - both statements will reference the data file in your current directory. (For example, It's a different story if the filename in question refers to an executable, i.e. is the first (or even only) thing you type on the command line.
|
|||
|
|
|
If you're running a program, If you're using that filename as an argument to a program as in |
|||
|
|
|
It depends what circumstances you're using it as. As an argument, eg "program filename", then it's up to the program, but generally they're identical. As a program name, eg "filename arguments", then "filename arguments" will search PATH to find the binary, while "./filename arguments" will use the program in the current directory. This is obviously useful if . isn't in the PATH, but it's also useful to use this one even if . is in the path, perhaps because it matches an earlier entry. |
|||
|
|
|
You are referring to command execution, right? There is an enviroment variable
When you type To execute a file by its path (especialy if it is not in $PATH) you can also type
|
|||
|
|
|
Executable security is the main reason for this difference. You do not want . (present working directory or PWD) in your path because someone could trojan http://en.wikipedia.org/wiki/Trojan_horse_%28computing%29 a crucial executable like ps or ls, in your PWD and fool you by presenting bad data. |
|||
|
|