What is ./ in BASH

I was playing around in a shell and typed ./. I go the following output:

bash: ./: Is a directory

It looks like "./" checks if a directory with the given name exist. I was trying to find documentation on this to see if my understanding was right, but can't find anything online. Can anyone explain this one to me?


Solution 1:

A general definition for this is likely not to be found in the Bash manual, but the POSIX specification (section Pathname Resolution):

The special filename dot shall refer to the directory specified by its predecessor.

Well, what is the predecessor if we only have .? I emphasized the important part:

If the pathname does not begin with a slash, the predecessor of the first filename of the pathname shall be taken to be the current working directory of the process

Also,

A pathname that contains at least one non-slash character and that ends with one or more trailing slashes shall be resolved as if a single dot character ( '.' ) were appended to the pathname

So, when you type ./ it is resolved as ./., which basically points to your current working directory. When you type something in your shell and hit Enter, the shell will try to execute the first part as a command. (Basically the first bunch of characters up until the first whitespace.)

There is no command or executable file called ./., so it will fail and tell you that ./ "is a directory". Interestingly, . is a command (it's a builtin also found as source), so when you just type . you'll get: bash: .: filename argument required.

Solution 2:

As others have written, ./ is the name of the current directory. When you typed ./ at the bash prompt and hit Enter, you attempted to execute the current directory as a command, which of course failed, and bash gave you the message (paraphrased), "I can't do that. ./ is a directory and I can't execute directories as commands."