Results 1 to 6 of 6
I'm currently studying BASH and can not see the connection of using "./". I assume it is supposed to represent my home directory but it will not work. I can ...
- 03-05-2011 #1
Use of ./ in BASH Etc.

I'm currently studying BASH and can not see the connection of using "./". I assume it is supposed to represent my home directory but it will not work. I can not use it to move a directory either like ../ but I do not have a guide that describes much at all.
Thanks in advance!
- 03-05-2011 #2
If I'm not mistaken, a ./ represents your present working directory. In other words, the directory in which the script is located/working from.
If your script is located in /home/foo/scripts/bash_script, then adding a ./ to your script would be a shorter way of referencing that directory.
So a single dot usually always references your present working directory. Two dots usually the directory just above your present working directory. A ~/ should reference your home directory, and when used in a script, I believe it references the home directory of the owner of that script.
Someone please correct me if I'm wrong.
I hope that helps! Enjoy your scripting
- 03-06-2011 #3
Thanks for the Reply!
While using this version
I don't have to use a "./" to address a relative path so I don't know what other reason the statement "./" is for.[kbs@localhost ~]$ /bin/bash --version
GNU bash, version 4.1.2(1)-release (i386-redhat-linux-gnu)
- 03-06-2011 #4Just Joined!
- Join Date
- Mar 2011
- Location
- Wales
- Posts
- 15
Afternoon, chaps.
The reason for the ./ thing is that it'll run a script in the current directory even if the latter is not in your path.
Type
If you see the period (.) somewhere in your path, for example like this...Code:echo $PATH
...then your current directory is in your path, which means you can run a script which is in your current directory without having to prefix its name with ./. Prefixing the name of your script with ./ is a fail-safe measure which ensures that the thing'll run even if the current directory's not in your path. (Folk use it when helping others or writing instructions in case the reader's path doesn't include the current directory.)Code:/home/paul/bin:.:/usr/local/bin:/usr/bin:/bin:/usr/share/texmf/bin
Note that the current directory isn't usually added to root's path variable for security reasons. (Use the first command above to compare root's path with an ordinary user's path.)
And Nagarjuna:
You're not wrong --- what you said was all quite right.Someone please correct me if I'm wrong
Cheerio!
- 03-07-2011 #5
I'd like to expand on Ignotum's post a bit.
First of all, adding '.' to PATH is generally considered to be a bad idea from a security perspective, for every user. The reason for this is that it allows any program to possibly create an executable called, for instance, "ls", that might be executed before the proper "ls", depending on how your PATH is configured. In general, you should use standard directories for your PATH (and you can include your own directories, as long as they are static), and then if you are executing anything not in one of those directories, you give the path.
Anyway, the whole './' prefix is, as has been said, in case the executable is not in your PATH. When you type a command into a shell, the first thing it does is checks if the command is simply a command name ("ls") or a path ("/bin/ls"). If it is a command name, PATH is searched. If it is a path, then only the file at that path is executed.
So if the command is in a subdirectory, you could always say "foo/bar/exe". However, if the executable is in the current directory, "exe" is not sufficient, as this is not a path. Therefore, "./exe" is a path that points to the current directory.DISTRO=Arch
Registered Linux User #388732
- 03-07-2011 #6
Thanks for sharing your expertise everyone. All of it has not sunken in but I think I grasp most of it.


Reply With Quote