What's the meaning of a dot before a command in shell?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
50
down vote

favorite
29












While following android eclipse debug tutorial, I encounter following commands.



cd /path/to/android/root 
. build/envsetup.sh
lunch 1
make
emulator


My problem is what the dot before build/envsetup.sh means?










share|improve this question



























    up vote
    50
    down vote

    favorite
    29












    While following android eclipse debug tutorial, I encounter following commands.



    cd /path/to/android/root 
    . build/envsetup.sh
    lunch 1
    make
    emulator


    My problem is what the dot before build/envsetup.sh means?










    share|improve this question

























      up vote
      50
      down vote

      favorite
      29









      up vote
      50
      down vote

      favorite
      29






      29





      While following android eclipse debug tutorial, I encounter following commands.



      cd /path/to/android/root 
      . build/envsetup.sh
      lunch 1
      make
      emulator


      My problem is what the dot before build/envsetup.sh means?










      share|improve this question















      While following android eclipse debug tutorial, I encounter following commands.



      cd /path/to/android/root 
      . build/envsetup.sh
      lunch 1
      make
      emulator


      My problem is what the dot before build/envsetup.sh means?







      shell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 9 '14 at 5:18









      slm♦

      241k66500668




      241k66500668










      asked Feb 9 '14 at 4:49









      Jichao

      397157




      397157




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          58
          down vote



          accepted










          A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.



          Example



          Say I had the following contents in a sample.sh file.



          $ cat sample.sh 
          echo "hi"
          echo "bye?"


          Now when I source it:



          $ . sample.sh 
          hi
          bye?
          $


          Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.



          Examples



          Say I had these commands in another file, addvars.sh.



          $ cat addvars.sh 
          export VAR1="some var1 string"
          export VAR2="some var2 string"


          Notice that I don't have any variables in my current shell's environment.



          $ env | grep VAR
          $


          Now when I source this file:



          $ . addvars.sh 
          $


          OK, doesn't seem like it did anything, but when we check the env variables again:



          $ env | grep VAR
          VAR1=some var1 string
          VAR2=some var2 string





          share|improve this answer





























            up vote
            49
            down vote













            To add to slm's answer:



            There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.



            For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:



            #!/bin/bash
            cd ~
            cd ..
            pwd


            So, let's call this script, oh, foo. And let's run this script as follows: ./foo



            We will see the following:



            /home


            (Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")



            Now, after running this script, let's type in this command



            pwd


            To see which directory we are in. We will see something like this:



            /home/username


            The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.



            Now, let's run the foo script like this



            . ./foo


            Or, equivalently:



            source ./foo


            If we do a pwd afterwards, we will see this:



            /home


            The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.




            Let me come up with a simpler example. Let's have a script that looks like this:



            #!/bin/bash
            exit


            Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:



            ./foo


            Nothing happens. However, on the other hand, if we do this:



            . ./foo


            Or this:



            source ./foo


            We log out.






            share|improve this answer


















            • 2




              Your answer is better than the accepted one, I understood how you explained, thanks!
              – Ahmed
              Jul 25 '16 at 13:03

















            up vote
            4
            down vote













            The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.






            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f114300%2fwhats-the-meaning-of-a-dot-before-a-command-in-shell%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              58
              down vote



              accepted










              A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.



              Example



              Say I had the following contents in a sample.sh file.



              $ cat sample.sh 
              echo "hi"
              echo "bye?"


              Now when I source it:



              $ . sample.sh 
              hi
              bye?
              $


              Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.



              Examples



              Say I had these commands in another file, addvars.sh.



              $ cat addvars.sh 
              export VAR1="some var1 string"
              export VAR2="some var2 string"


              Notice that I don't have any variables in my current shell's environment.



              $ env | grep VAR
              $


              Now when I source this file:



              $ . addvars.sh 
              $


              OK, doesn't seem like it did anything, but when we check the env variables again:



              $ env | grep VAR
              VAR1=some var1 string
              VAR2=some var2 string





              share|improve this answer


























                up vote
                58
                down vote



                accepted










                A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.



                Example



                Say I had the following contents in a sample.sh file.



                $ cat sample.sh 
                echo "hi"
                echo "bye?"


                Now when I source it:



                $ . sample.sh 
                hi
                bye?
                $


                Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.



                Examples



                Say I had these commands in another file, addvars.sh.



                $ cat addvars.sh 
                export VAR1="some var1 string"
                export VAR2="some var2 string"


                Notice that I don't have any variables in my current shell's environment.



                $ env | grep VAR
                $


                Now when I source this file:



                $ . addvars.sh 
                $


                OK, doesn't seem like it did anything, but when we check the env variables again:



                $ env | grep VAR
                VAR1=some var1 string
                VAR2=some var2 string





                share|improve this answer
























                  up vote
                  58
                  down vote



                  accepted







                  up vote
                  58
                  down vote



                  accepted






                  A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.



                  Example



                  Say I had the following contents in a sample.sh file.



                  $ cat sample.sh 
                  echo "hi"
                  echo "bye?"


                  Now when I source it:



                  $ . sample.sh 
                  hi
                  bye?
                  $


                  Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.



                  Examples



                  Say I had these commands in another file, addvars.sh.



                  $ cat addvars.sh 
                  export VAR1="some var1 string"
                  export VAR2="some var2 string"


                  Notice that I don't have any variables in my current shell's environment.



                  $ env | grep VAR
                  $


                  Now when I source this file:



                  $ . addvars.sh 
                  $


                  OK, doesn't seem like it did anything, but when we check the env variables again:



                  $ env | grep VAR
                  VAR1=some var1 string
                  VAR2=some var2 string





                  share|improve this answer














                  A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms.



                  Example



                  Say I had the following contents in a sample.sh file.



                  $ cat sample.sh 
                  echo "hi"
                  echo "bye?"


                  Now when I source it:



                  $ . sample.sh 
                  hi
                  bye?
                  $


                  Files such as this are often used to incorporate setup commands such as adding things to ones environment variables.



                  Examples



                  Say I had these commands in another file, addvars.sh.



                  $ cat addvars.sh 
                  export VAR1="some var1 string"
                  export VAR2="some var2 string"


                  Notice that I don't have any variables in my current shell's environment.



                  $ env | grep VAR
                  $


                  Now when I source this file:



                  $ . addvars.sh 
                  $


                  OK, doesn't seem like it did anything, but when we check the env variables again:



                  $ env | grep VAR
                  VAR1=some var1 string
                  VAR2=some var2 string






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 13 '15 at 6:30









                  Slothworks

                  384316




                  384316










                  answered Feb 9 '14 at 5:01









                  slm♦

                  241k66500668




                  241k66500668






















                      up vote
                      49
                      down vote













                      To add to slm's answer:



                      There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.



                      For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:



                      #!/bin/bash
                      cd ~
                      cd ..
                      pwd


                      So, let's call this script, oh, foo. And let's run this script as follows: ./foo



                      We will see the following:



                      /home


                      (Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")



                      Now, after running this script, let's type in this command



                      pwd


                      To see which directory we are in. We will see something like this:



                      /home/username


                      The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.



                      Now, let's run the foo script like this



                      . ./foo


                      Or, equivalently:



                      source ./foo


                      If we do a pwd afterwards, we will see this:



                      /home


                      The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.




                      Let me come up with a simpler example. Let's have a script that looks like this:



                      #!/bin/bash
                      exit


                      Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:



                      ./foo


                      Nothing happens. However, on the other hand, if we do this:



                      . ./foo


                      Or this:



                      source ./foo


                      We log out.






                      share|improve this answer


















                      • 2




                        Your answer is better than the accepted one, I understood how you explained, thanks!
                        – Ahmed
                        Jul 25 '16 at 13:03














                      up vote
                      49
                      down vote













                      To add to slm's answer:



                      There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.



                      For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:



                      #!/bin/bash
                      cd ~
                      cd ..
                      pwd


                      So, let's call this script, oh, foo. And let's run this script as follows: ./foo



                      We will see the following:



                      /home


                      (Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")



                      Now, after running this script, let's type in this command



                      pwd


                      To see which directory we are in. We will see something like this:



                      /home/username


                      The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.



                      Now, let's run the foo script like this



                      . ./foo


                      Or, equivalently:



                      source ./foo


                      If we do a pwd afterwards, we will see this:



                      /home


                      The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.




                      Let me come up with a simpler example. Let's have a script that looks like this:



                      #!/bin/bash
                      exit


                      Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:



                      ./foo


                      Nothing happens. However, on the other hand, if we do this:



                      . ./foo


                      Or this:



                      source ./foo


                      We log out.






                      share|improve this answer


















                      • 2




                        Your answer is better than the accepted one, I understood how you explained, thanks!
                        – Ahmed
                        Jul 25 '16 at 13:03












                      up vote
                      49
                      down vote










                      up vote
                      49
                      down vote









                      To add to slm's answer:



                      There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.



                      For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:



                      #!/bin/bash
                      cd ~
                      cd ..
                      pwd


                      So, let's call this script, oh, foo. And let's run this script as follows: ./foo



                      We will see the following:



                      /home


                      (Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")



                      Now, after running this script, let's type in this command



                      pwd


                      To see which directory we are in. We will see something like this:



                      /home/username


                      The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.



                      Now, let's run the foo script like this



                      . ./foo


                      Or, equivalently:



                      source ./foo


                      If we do a pwd afterwards, we will see this:



                      /home


                      The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.




                      Let me come up with a simpler example. Let's have a script that looks like this:



                      #!/bin/bash
                      exit


                      Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:



                      ./foo


                      Nothing happens. However, on the other hand, if we do this:



                      . ./foo


                      Or this:



                      source ./foo


                      We log out.






                      share|improve this answer














                      To add to slm's answer:



                      There are two ways to run a shell script. One is to run the script in a separate process, which means anything about the shell's environment (memory state) will revert to the state of the "parent" shell before running the "child" shell process.



                      For example, the current working directory (the location in the filesystem one is in) is determined on a per-process basis. So, let's have a script that looks like this:



                      #!/bin/bash
                      cd ~
                      cd ..
                      pwd


                      So, let's call this script, oh, foo. And let's run this script as follows: ./foo



                      We will see the following:



                      /home


                      (Standard disclaimer that there are a large number of Linux and other UNIX clone distributions out there, some of which do not put user's directories in /home. Or, as we used to say "Your mileage may vary")



                      Now, after running this script, let's type in this command



                      pwd


                      To see which directory we are in. We will see something like this:



                      /home/username


                      The reason being, again, the shell script we ran had its own environment (including its own directory where commands were being run), and that environment went away once the script finished running.



                      Now, let's run the foo script like this



                      . ./foo


                      Or, equivalently:



                      source ./foo


                      If we do a pwd afterwards, we will see this:



                      /home


                      The reason being: Sourcing a script doesn't call a separate process. It is like typing all of the commands in the parent process by hand; its environment is preserved after the script ends.




                      Let me come up with a simpler example. Let's have a script that looks like this:



                      #!/bin/bash
                      exit


                      Let's name it foo. Let's make sure we can run it: chmod 755 foo. Then, let's run it like this:



                      ./foo


                      Nothing happens. However, on the other hand, if we do this:



                      . ./foo


                      Or this:



                      source ./foo


                      We log out.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 3 '15 at 13:35









                      dhag

                      10.9k32742




                      10.9k32742










                      answered Feb 9 '14 at 5:45









                      samiam

                      2,346713




                      2,346713







                      • 2




                        Your answer is better than the accepted one, I understood how you explained, thanks!
                        – Ahmed
                        Jul 25 '16 at 13:03












                      • 2




                        Your answer is better than the accepted one, I understood how you explained, thanks!
                        – Ahmed
                        Jul 25 '16 at 13:03







                      2




                      2




                      Your answer is better than the accepted one, I understood how you explained, thanks!
                      – Ahmed
                      Jul 25 '16 at 13:03




                      Your answer is better than the accepted one, I understood how you explained, thanks!
                      – Ahmed
                      Jul 25 '16 at 13:03










                      up vote
                      4
                      down vote













                      The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.






                      share|improve this answer


























                        up vote
                        4
                        down vote













                        The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.






                        share|improve this answer
























                          up vote
                          4
                          down vote










                          up vote
                          4
                          down vote









                          The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.






                          share|improve this answer














                          The period (dot) is short hand for the bash built in source. It will read and execute commands from a file in the current environment and return the exit status of the last command executed. The files can be in the current directory or anywhere in the PATH. It does not need to be executable.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 13 mins ago









                          Andrii Abramov

                          1033




                          1033










                          answered May 3 '15 at 13:44









                          tlund

                          33518




                          33518



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f114300%2fwhats-the-meaning-of-a-dot-before-a-command-in-shell%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              Peggy Mitchell

                              The Forum (Inglewood, California)

                              Palaiologos