Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    10

    [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

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,569
    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 .bashrc
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

  3. #3
    Linux Guru Jonathan183's Avatar
    Join Date
    Oct 2007
    Posts
    3,043
    You may find this thread helps as well

  4. #4
    Just Joined!
    Join Date
    Sep 2008
    Posts
    13
    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

  5. #5
    Just Joined!
    Join Date
    Dec 2009
    Posts
    10
    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 ?

  6. #6
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Quote Originally Posted by javanoob View Post
    well i didnt include the #!/bin/bash but it still works,
    why ?
    All that line does is tell the interpreter which shell to use to execute the script. If you don't supply one, it will execute in your default shell (i.e. $SHELL).

  7. #7
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    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.

  8. #8
    Just Joined!
    Join Date
    Dec 2009
    Posts
    10
    oh my god..

    thank you guys. such a wonderful bunch of helpful peeps!

    i have understood my question . thanks a million.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •