Results 1 to 8 of 8
hi guys,
1st question)
can i know the meaning / difference
of
1) .
2) ./
everytime i saw people executing a script, they will do ./scriptname.sh
does . means ...
- 02-18-2010 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 6
[SOLVED] the meaning of . and ./ - from a noob
hi guys,
1st question)
can i know the meaning / difference
of
1) .
2) ./
everytime i saw people executing a script, they will do ./scriptname.sh
does . means current directory ? or ?
2nd question)
i added a function in .bashrc,
however it is not appearing for usage until i type a
. .bashrc
so does . means load ?
however i cant do a ./.bashrc
what is the difference between load and execute ?
please help i am confused

Thanks alot
Regards,
Noob
- 02-18-2010 #2
1. when you do ./scriptname.sh the . means in this directory and the / is the separator between the directory and file.
2. When a file starts with a . as in .bashrc that simply means the file is hidden. I'm not sure avout the ..bashrc vs ./.bashrc thing. Logically, I would expect the ./.bashrc to work
OK ./.bashrc works for me but I had to set the execute bit by using chmod +x .bashrcIf we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 02-18-2010 #3
You may find this thread helps as well
- 02-19-2010 #4Just Joined!
- Join Date
- Sep 2008
- Posts
- 12
To source ( '.' ) a file means that you expand it's contents into the current shell. If you just run it, then it'll fork off a new shell to run it. So, if you're setting up an enviroment, forking is - well - forking useless.
When you log in, *every* interactive user runs, with root privileges, /etc/profile. Depending on the shell, a local version of this ( note the hidden files... ) - originally .profile, for the old faithful /bin/sh shell, .cshrc for the c shell, and most likely these days, .bash_profile for the Bourne Again Shell. [ note this is a bit simplified, but you get the idea (: ]
It is also possible to start up a shell without logging in, and this is where the .bashrc file is automagically run. However, a log of installations source .bashrc from .bash_profile so it gets run on login as well.
Any of these files can be sourced manually at any time, hence your functions not turning up until you do so.
hth, Steve
- 02-19-2010 #5Just Joined!
- Join Date
- Dec 2009
- Posts
- 6
hi guys,
thanks for the threads..
while reading on..
i understand that
./ means to tell the OS that the file is executable, and it will use the 1st line
#! /bin/bash to interpret the script.
however i done a v simple script.
cat > abc.sh
echo "arhh"
ctrl ^D
]$ chmod 755 abc.sh
]$ ./abc.sh
arhh
------------------
well i didnt include the #!/bin/bash but it still works,
why ?
- 02-19-2010 #6
- 02-19-2010 #7
Hopefully I can give you a better understanding:
In UNIX, . refers to the current directory, and .. the parent directory. That is why cd .. moves you to the parent directory. The reason . is included is to allow you to specify the current directory when running executables. If you type rm, the shell will run the rm in /bin, since that directory is in the path. Now what if you had a program (set +x mode) in your current directory that is also called rm? Well, due to security considerations the current directory is not included in the path (just in case the local rm was malicious), so you must include either the full path or the relative path to the file. And if it is in the current directory, the fastest way to run it is to use the relative path, ./rm.
. used to load a file is a bash thing I think. It is equivalent to typing "source FILE", but faster to type.
The #! is called the shabang, and that byte sequence is actually a magic number that tells the operating system what kind of file it is. The file won't run though unless it is set executable (+x), and the shabang is pretty much optional for regular shell scripts, but if you have a perl or awk script or something, you'll want it to run in their interpreters rather than the shell, and would thus include the appropriate path after the shabang.
- 02-19-2010 #8Just Joined!
- Join Date
- Dec 2009
- Posts
- 6
oh my god..
thank you guys. such a wonderful bunch of helpful peeps!
i have understood my question . thanks a million.



