What does 'source' do?











up vote
512
down vote

favorite
163












$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]


It exists, and it is runnable. Why isn't there any documentation about it in Ubuntu?
What does it do? How can I install documentation about it?










share|improve this question




















  • 4




    related: superuser.com/questions/176783/…
    – lesmana
    Jan 17 '11 at 21:59






  • 45




    you forgot $ type source source is a shell built-in
    – bnjmn
    Oct 9 '13 at 6:00








  • 1




    My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented.
    – arielnmz
    Aug 20 '14 at 12:29








  • 2




    @lesmana, great link. That linked answer is the more thorough answer to this question.
    – Scott
    Sep 5 '14 at 15:02






  • 1




    Try "help source"
    – Jasser
    Sep 19 '15 at 14:12















up vote
512
down vote

favorite
163












$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]


It exists, and it is runnable. Why isn't there any documentation about it in Ubuntu?
What does it do? How can I install documentation about it?










share|improve this question




















  • 4




    related: superuser.com/questions/176783/…
    – lesmana
    Jan 17 '11 at 21:59






  • 45




    you forgot $ type source source is a shell built-in
    – bnjmn
    Oct 9 '13 at 6:00








  • 1




    My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented.
    – arielnmz
    Aug 20 '14 at 12:29








  • 2




    @lesmana, great link. That linked answer is the more thorough answer to this question.
    – Scott
    Sep 5 '14 at 15:02






  • 1




    Try "help source"
    – Jasser
    Sep 19 '15 at 14:12













up vote
512
down vote

favorite
163









up vote
512
down vote

favorite
163






163





$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]


It exists, and it is runnable. Why isn't there any documentation about it in Ubuntu?
What does it do? How can I install documentation about it?










share|improve this question















$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]


It exists, and it is runnable. Why isn't there any documentation about it in Ubuntu?
What does it do? How can I install documentation about it?







bash shell documentation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 5 '14 at 19:36









Ben Crowell

337212




337212










asked Sep 24 '09 at 10:35









Andrea Ambu

2,99742020




2,99742020








  • 4




    related: superuser.com/questions/176783/…
    – lesmana
    Jan 17 '11 at 21:59






  • 45




    you forgot $ type source source is a shell built-in
    – bnjmn
    Oct 9 '13 at 6:00








  • 1




    My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented.
    – arielnmz
    Aug 20 '14 at 12:29








  • 2




    @lesmana, great link. That linked answer is the more thorough answer to this question.
    – Scott
    Sep 5 '14 at 15:02






  • 1




    Try "help source"
    – Jasser
    Sep 19 '15 at 14:12














  • 4




    related: superuser.com/questions/176783/…
    – lesmana
    Jan 17 '11 at 21:59






  • 45




    you forgot $ type source source is a shell built-in
    – bnjmn
    Oct 9 '13 at 6:00








  • 1




    My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented.
    – arielnmz
    Aug 20 '14 at 12:29








  • 2




    @lesmana, great link. That linked answer is the more thorough answer to this question.
    – Scott
    Sep 5 '14 at 15:02






  • 1




    Try "help source"
    – Jasser
    Sep 19 '15 at 14:12








4




4




related: superuser.com/questions/176783/…
– lesmana
Jan 17 '11 at 21:59




related: superuser.com/questions/176783/…
– lesmana
Jan 17 '11 at 21:59




45




45




you forgot $ type source source is a shell built-in
– bnjmn
Oct 9 '13 at 6:00






you forgot $ type source source is a shell built-in
– bnjmn
Oct 9 '13 at 6:00






1




1




My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented.
– arielnmz
Aug 20 '14 at 12:29






My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented.
– arielnmz
Aug 20 '14 at 12:29






2




2




@lesmana, great link. That linked answer is the more thorough answer to this question.
– Scott
Sep 5 '14 at 15:02




@lesmana, great link. That linked answer is the more thorough answer to this question.
– Scott
Sep 5 '14 at 15:02




1




1




Try "help source"
– Jasser
Sep 19 '15 at 14:12




Try "help source"
– Jasser
Sep 19 '15 at 14:12










11 Answers
11






active

oldest

votes

















up vote
420
down vote



accepted










source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period).




Syntax



. filename [arguments]

source filename [arguments]






share|improve this answer



















  • 5




    Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
    – Jonik
    Sep 24 '09 at 11:17






  • 2




    Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
    – nagul
    Sep 24 '09 at 11:47






  • 11




    @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
    – jlliagre
    Aug 2 '13 at 14:02






  • 16




    @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
    – Rich Homolka
    Mar 10 '14 at 18:31






  • 3




    One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
    – LawrenceC
    Mar 10 '14 at 18:41


















up vote
242
down vote













Be careful! ./ and source are not quite the same.





  • ./script runs the script as an executable file, launching a new shell to run it


  • source script reads and executes commands from filename in the current shell environment


Note: ./script is not . script, but . script == source script



https://askubuntu.com/questions/182012/is-there-a-difference-between-and-source-in-bash-after-all?lq=1






share|improve this answer



















  • 24




    You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
    – Joakim Elofsson
    Aug 1 '13 at 13:14






  • 2




    @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
    – damphat
    Aug 2 '13 at 11:45






  • 1




    It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
    – Daniel F
    Dec 6 '17 at 12:51


















up vote
82
down vote













It is useful to know the 'type' command:



> type source
source is a shell builtin


whenever something is a shell builtin it is time to do man bash.






share|improve this answer

















  • 1




    Always know something new when reading man )
    – user83293
    Aug 15 '13 at 8:41






  • 17




    You can also use help {builtin-name}, i.e. help source.
    – LawrenceC
    Mar 10 '14 at 18:39






  • 1




    help doesn't work everywhere (atleast in zsh). type does.
    – kumar_harsh
    Mar 28 '14 at 8:35






  • 2




    To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
    – Ron Burk
    Apr 29 '15 at 19:43


















up vote
34
down vote













. (a period) is a bash shell built-in command that executes the commands from a file passed as argument, in the current shell. 'source' is a synonym for '.'.



From Bash man page:



. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell
environment and return the exit status of the last command exe‐
cuted from filename. If filename does not contain a slash, file
names in PATH are used to find the directory containing file‐
name. The file searched for in PATH need not be executable.
When bash is not in posix mode, the current directory is
searched if no file is found in PATH. If the sourcepath option
to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the posi‐
tional parameters when filename is executed. Otherwise the
positional parameters are unchanged. The return status is the
status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or
cannot be read.





share|improve this answer






























    up vote
    20
    down vote













    'source' is the long version of '.' command. On the bash prompt one can do:



    source ~/.bashrc


    to reload your (changed?) bash setting for current running bash.



    Short version would be:



    . ~/.bashrc


    The man page:



    . filename [arguments]
    source filename [arguments]
    Read and execute commands from filename in the current shell environment and
    return the exit status of the last command executed from filename. If
    filename does not contain a slash, file names in PATH are used to find the
    directory containing filename. The file searched for in PATH need not be
    executable. When bash is not in posix mode, the current directory is
    searched if no file is found in PATH. If the sourcepath option to the short
    builtin command is turned off, the PATH is not searched. If any arguments
    are supplied, they become the positional parameters when filename is
    executed. Otherwise the positional parameters are unchanged. The return
    status is the status of the last command exited within the script (0 if no
    commands are executed), and false if filename is not found or cannot be
    read.





    share|improve this answer























    • This should be the accepted answer.
      – Peter Mortensen
      Mar 19 '17 at 8:00


















    up vote
    19
    down vote













    source command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./ executes the provided executable script in a new shell.



    source command do have a synonym . filename.



    To make it more clear, have a look at the following script, which sets the alias.



    make_alias



    #! /bin/bash

    alias myproject='cd ~/Documents/Projects/2015/NewProject'


    Now we have two choices to execute this script. But with only one option, the desired alias for current shell can be created among these two options.



    Option 1: ./make_alias



    Make script executable first.



    chmod +x make_alias


    Execute



    ./make_alias


    Verify



    alias


    Output



    **nothing**


    Whoops! Alias is gone with the new shell.



    Let's go with the second option.



    Option 2: source make_alias



    Execute



    source make_alias


    or



    . make_alias


    Verify



    alias


    Output



    alias myproject='cd ~/Documents/Projects/2015/NewProject'


    Yeah Alias is set.






    share|improve this answer




























      up vote
      5
      down vote













      When in doubt, the best thing to do is use the info command:



      [root@abc ~]# info source

      BASH BUILTIN COMMANDS
      Unless otherwise noted, each builtin command documented in this section
      as accepting options preceded by - accepts -- to signify the end of the
      options. The :, true, false, and test builtins do not accept options
      and do not treat -- specially. The exit, logout, break, continue, let,
      and shift builtins accept and process arguments beginning with - with-
      out requiring --. Other builtins that accept arguments but are not
      specified as accepting options interpret arguments beginning with - as
      invalid options and require -- to prevent this interpretation.
      : [arguments]
      No effect; the command does nothing beyond expanding arguments
      and performing any specified redirections. A zero exit code is
      returned.

      . filename [arguments]
      source filename [arguments]
      Read and execute commands from filename in the current shell
      environment and return the exit status of the last command exe-
      cuted from filename. If filename does not contain a slash, file
      names in PATH are used to find the directory containing file-
      name. The file searched for in PATH need not be executable.
      When bash is not in posix mode, the current directory is
      searched if no file is found in PATH. If the sourcepath option
      to the shopt builtin command is turned off, the PATH is not
      searched. If any arguments are supplied, they become the posi-
      tional parameters when filename is executed. Otherwise the
      positional parameters are unchanged. The return status is the
      status of the last command exited within the script (0 if no
      commands are executed), and false if filename is not found or
      cannot be read.





      share|improve this answer























      • Could you provide more than just RTFM?
        – Peter Mortensen
        Mar 19 '17 at 9:04


















      up vote
      3
      down vote













      Type the command "help source" in your shell.



      You will get output like this:



      source: source filename [arguments]

      Execute commands from a file in the current shell.

      Read and execute commands from FILENAME in the current shell. The
      entries in $PATH are used to find the directory containing FILENAME.
      If any ARGUMENTS are supplied, they become the positional parameters
      when FILENAME is executed.

      Exit Status:
      Returns the status of the last command executed in FILENAME; fails if
      FILENAME cannot be read.





      share|improve this answer






























        up vote
        2
        down vote













        From the Linux Documentation Project, Advanced Bash Scripting Guide,

        Chapter 15 - Internals Commands and Builtins:




        source, . (dot command):

        This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

        If the sourced file is itself an executable script, then it will run, then return control to the script that called it. A sourced executable script may use a return for this purpose.




        So, for those familiar with C programming language, sourcing a file has an effect similar to the #include directive.



        Note also that you may pass positional arguments to the file being sourced, like:



        $ source $filename $arg1 arg2





        share|improve this answer





















        • How does this answer differ from the 9 previous answers?
          – Stephen Rauch
          Jun 12 '17 at 0:31






        • 1




          I add another source of information and additional information not mentioned before.
          – Alexandro de Oliveira
          Jun 12 '17 at 1:16


















        up vote
        1
        down vote













        It should be noted that although being an awesome command, neither source nor its shorthand of . would source more than one file, meaning



        source *.sh


        or



        . script1.sh script2.sh


        will not work.



        We can fall back using for loops, but it would issue the executable many times, creating multiple commands or issue of it.



        Conclusion: source doesn't take multiple files as input. The argument has to be one.



        Which sucks IMHO.






        share|improve this answer






























          up vote
          0
          down vote













          With source you can pass variables or functions from another file in to your script and use them without having to write them again.



          F.I:



          #!/bin/bash

          source /etc/environment

          source /myscripts/jetty-common/config/jetty-functions.sh


          Cheers






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f46139%2fwhat-does-source-do%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            11 Answers
            11






            active

            oldest

            votes








            11 Answers
            11






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            420
            down vote



            accepted










            source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period).




            Syntax



            . filename [arguments]

            source filename [arguments]






            share|improve this answer



















            • 5




              Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
              – Jonik
              Sep 24 '09 at 11:17






            • 2




              Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
              – nagul
              Sep 24 '09 at 11:47






            • 11




              @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
              – jlliagre
              Aug 2 '13 at 14:02






            • 16




              @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
              – Rich Homolka
              Mar 10 '14 at 18:31






            • 3




              One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
              – LawrenceC
              Mar 10 '14 at 18:41















            up vote
            420
            down vote



            accepted










            source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period).




            Syntax



            . filename [arguments]

            source filename [arguments]






            share|improve this answer



















            • 5




              Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
              – Jonik
              Sep 24 '09 at 11:17






            • 2




              Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
              – nagul
              Sep 24 '09 at 11:47






            • 11




              @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
              – jlliagre
              Aug 2 '13 at 14:02






            • 16




              @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
              – Rich Homolka
              Mar 10 '14 at 18:31






            • 3




              One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
              – LawrenceC
              Mar 10 '14 at 18:41













            up vote
            420
            down vote



            accepted







            up vote
            420
            down vote



            accepted






            source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period).




            Syntax



            . filename [arguments]

            source filename [arguments]






            share|improve this answer














            source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period).




            Syntax



            . filename [arguments]

            source filename [arguments]







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 8 '17 at 6:39









            Marc.2377

            509830




            509830










            answered Sep 24 '09 at 10:47









            nagul

            23.6k76271




            23.6k76271








            • 5




              Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
              – Jonik
              Sep 24 '09 at 11:17






            • 2




              Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
              – nagul
              Sep 24 '09 at 11:47






            • 11




              @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
              – jlliagre
              Aug 2 '13 at 14:02






            • 16




              @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
              – Rich Homolka
              Mar 10 '14 at 18:31






            • 3




              One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
              – LawrenceC
              Mar 10 '14 at 18:41














            • 5




              Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
              – Jonik
              Sep 24 '09 at 11:17






            • 2




              Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
              – nagul
              Sep 24 '09 at 11:47






            • 11




              @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
              – jlliagre
              Aug 2 '13 at 14:02






            • 16




              @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
              – Rich Homolka
              Mar 10 '14 at 18:31






            • 3




              One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
              – LawrenceC
              Mar 10 '14 at 18:41








            5




            5




            Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
            – Jonik
            Sep 24 '09 at 11:17




            Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...)
            – Jonik
            Sep 24 '09 at 11:17




            2




            2




            Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
            – nagul
            Sep 24 '09 at 11:47




            Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it.
            – nagul
            Sep 24 '09 at 11:47




            11




            11




            @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
            – jlliagre
            Aug 2 '13 at 14:02




            @nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies.
            – jlliagre
            Aug 2 '13 at 14:02




            16




            16




            @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
            – Rich Homolka
            Mar 10 '14 at 18:31




            @jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email.
            – Rich Homolka
            Mar 10 '14 at 18:31




            3




            3




            One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
            – LawrenceC
            Mar 10 '14 at 18:41




            One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values.
            – LawrenceC
            Mar 10 '14 at 18:41












            up vote
            242
            down vote













            Be careful! ./ and source are not quite the same.





            • ./script runs the script as an executable file, launching a new shell to run it


            • source script reads and executes commands from filename in the current shell environment


            Note: ./script is not . script, but . script == source script



            https://askubuntu.com/questions/182012/is-there-a-difference-between-and-source-in-bash-after-all?lq=1






            share|improve this answer



















            • 24




              You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
              – Joakim Elofsson
              Aug 1 '13 at 13:14






            • 2




              @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
              – damphat
              Aug 2 '13 at 11:45






            • 1




              It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
              – Daniel F
              Dec 6 '17 at 12:51















            up vote
            242
            down vote













            Be careful! ./ and source are not quite the same.





            • ./script runs the script as an executable file, launching a new shell to run it


            • source script reads and executes commands from filename in the current shell environment


            Note: ./script is not . script, but . script == source script



            https://askubuntu.com/questions/182012/is-there-a-difference-between-and-source-in-bash-after-all?lq=1






            share|improve this answer



















            • 24




              You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
              – Joakim Elofsson
              Aug 1 '13 at 13:14






            • 2




              @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
              – damphat
              Aug 2 '13 at 11:45






            • 1




              It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
              – Daniel F
              Dec 6 '17 at 12:51













            up vote
            242
            down vote










            up vote
            242
            down vote









            Be careful! ./ and source are not quite the same.





            • ./script runs the script as an executable file, launching a new shell to run it


            • source script reads and executes commands from filename in the current shell environment


            Note: ./script is not . script, but . script == source script



            https://askubuntu.com/questions/182012/is-there-a-difference-between-and-source-in-bash-after-all?lq=1






            share|improve this answer














            Be careful! ./ and source are not quite the same.





            • ./script runs the script as an executable file, launching a new shell to run it


            • source script reads and executes commands from filename in the current shell environment


            Note: ./script is not . script, but . script == source script



            https://askubuntu.com/questions/182012/is-there-a-difference-between-and-source-in-bash-after-all?lq=1







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:22









            Community

            1




            1










            answered Jul 11 '13 at 13:24









            damphat

            2,545186




            2,545186








            • 24




              You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
              – Joakim Elofsson
              Aug 1 '13 at 13:14






            • 2




              @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
              – damphat
              Aug 2 '13 at 11:45






            • 1




              It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
              – Daniel F
              Dec 6 '17 at 12:51














            • 24




              You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
              – Joakim Elofsson
              Aug 1 '13 at 13:14






            • 2




              @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
              – damphat
              Aug 2 '13 at 11:45






            • 1




              It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
              – Daniel F
              Dec 6 '17 at 12:51








            24




            24




            You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
            – Joakim Elofsson
            Aug 1 '13 at 13:14




            You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link.
            – Joakim Elofsson
            Aug 1 '13 at 13:14




            2




            2




            @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
            – damphat
            Aug 2 '13 at 11:45




            @JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it.
            – damphat
            Aug 2 '13 at 11:45




            1




            1




            It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
            – Daniel F
            Dec 6 '17 at 12:51




            It's kind of important that the accepted answer also points to this one, because for a moment I thought that ./ == source == .
            – Daniel F
            Dec 6 '17 at 12:51










            up vote
            82
            down vote













            It is useful to know the 'type' command:



            > type source
            source is a shell builtin


            whenever something is a shell builtin it is time to do man bash.






            share|improve this answer

















            • 1




              Always know something new when reading man )
              – user83293
              Aug 15 '13 at 8:41






            • 17




              You can also use help {builtin-name}, i.e. help source.
              – LawrenceC
              Mar 10 '14 at 18:39






            • 1




              help doesn't work everywhere (atleast in zsh). type does.
              – kumar_harsh
              Mar 28 '14 at 8:35






            • 2




              To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
              – Ron Burk
              Apr 29 '15 at 19:43















            up vote
            82
            down vote













            It is useful to know the 'type' command:



            > type source
            source is a shell builtin


            whenever something is a shell builtin it is time to do man bash.






            share|improve this answer

















            • 1




              Always know something new when reading man )
              – user83293
              Aug 15 '13 at 8:41






            • 17




              You can also use help {builtin-name}, i.e. help source.
              – LawrenceC
              Mar 10 '14 at 18:39






            • 1




              help doesn't work everywhere (atleast in zsh). type does.
              – kumar_harsh
              Mar 28 '14 at 8:35






            • 2




              To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
              – Ron Burk
              Apr 29 '15 at 19:43













            up vote
            82
            down vote










            up vote
            82
            down vote









            It is useful to know the 'type' command:



            > type source
            source is a shell builtin


            whenever something is a shell builtin it is time to do man bash.






            share|improve this answer












            It is useful to know the 'type' command:



            > type source
            source is a shell builtin


            whenever something is a shell builtin it is time to do man bash.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 9 '13 at 15:45









            micans

            94966




            94966








            • 1




              Always know something new when reading man )
              – user83293
              Aug 15 '13 at 8:41






            • 17




              You can also use help {builtin-name}, i.e. help source.
              – LawrenceC
              Mar 10 '14 at 18:39






            • 1




              help doesn't work everywhere (atleast in zsh). type does.
              – kumar_harsh
              Mar 28 '14 at 8:35






            • 2




              To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
              – Ron Burk
              Apr 29 '15 at 19:43














            • 1




              Always know something new when reading man )
              – user83293
              Aug 15 '13 at 8:41






            • 17




              You can also use help {builtin-name}, i.e. help source.
              – LawrenceC
              Mar 10 '14 at 18:39






            • 1




              help doesn't work everywhere (atleast in zsh). type does.
              – kumar_harsh
              Mar 28 '14 at 8:35






            • 2




              To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
              – Ron Burk
              Apr 29 '15 at 19:43








            1




            1




            Always know something new when reading man )
            – user83293
            Aug 15 '13 at 8:41




            Always know something new when reading man )
            – user83293
            Aug 15 '13 at 8:41




            17




            17




            You can also use help {builtin-name}, i.e. help source.
            – LawrenceC
            Mar 10 '14 at 18:39




            You can also use help {builtin-name}, i.e. help source.
            – LawrenceC
            Mar 10 '14 at 18:39




            1




            1




            help doesn't work everywhere (atleast in zsh). type does.
            – kumar_harsh
            Mar 28 '14 at 8:35




            help doesn't work everywhere (atleast in zsh). type does.
            – kumar_harsh
            Mar 28 '14 at 8:35




            2




            2




            To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
            – Ron Burk
            Apr 29 '15 at 19:43




            To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text.
            – Ron Burk
            Apr 29 '15 at 19:43










            up vote
            34
            down vote













            . (a period) is a bash shell built-in command that executes the commands from a file passed as argument, in the current shell. 'source' is a synonym for '.'.



            From Bash man page:



            . filename [arguments]
            source filename [arguments]
            Read and execute commands from filename in the current shell
            environment and return the exit status of the last command exe‐
            cuted from filename. If filename does not contain a slash, file
            names in PATH are used to find the directory containing file‐
            name. The file searched for in PATH need not be executable.
            When bash is not in posix mode, the current directory is
            searched if no file is found in PATH. If the sourcepath option
            to the shopt builtin command is turned off, the PATH is not
            searched. If any arguments are supplied, they become the posi‐
            tional parameters when filename is executed. Otherwise the
            positional parameters are unchanged. The return status is the
            status of the last command exited within the script (0 if no
            commands are executed), and false if filename is not found or
            cannot be read.





            share|improve this answer



























              up vote
              34
              down vote













              . (a period) is a bash shell built-in command that executes the commands from a file passed as argument, in the current shell. 'source' is a synonym for '.'.



              From Bash man page:



              . filename [arguments]
              source filename [arguments]
              Read and execute commands from filename in the current shell
              environment and return the exit status of the last command exe‐
              cuted from filename. If filename does not contain a slash, file
              names in PATH are used to find the directory containing file‐
              name. The file searched for in PATH need not be executable.
              When bash is not in posix mode, the current directory is
              searched if no file is found in PATH. If the sourcepath option
              to the shopt builtin command is turned off, the PATH is not
              searched. If any arguments are supplied, they become the posi‐
              tional parameters when filename is executed. Otherwise the
              positional parameters are unchanged. The return status is the
              status of the last command exited within the script (0 if no
              commands are executed), and false if filename is not found or
              cannot be read.





              share|improve this answer

























                up vote
                34
                down vote










                up vote
                34
                down vote









                . (a period) is a bash shell built-in command that executes the commands from a file passed as argument, in the current shell. 'source' is a synonym for '.'.



                From Bash man page:



                . filename [arguments]
                source filename [arguments]
                Read and execute commands from filename in the current shell
                environment and return the exit status of the last command exe‐
                cuted from filename. If filename does not contain a slash, file
                names in PATH are used to find the directory containing file‐
                name. The file searched for in PATH need not be executable.
                When bash is not in posix mode, the current directory is
                searched if no file is found in PATH. If the sourcepath option
                to the shopt builtin command is turned off, the PATH is not
                searched. If any arguments are supplied, they become the posi‐
                tional parameters when filename is executed. Otherwise the
                positional parameters are unchanged. The return status is the
                status of the last command exited within the script (0 if no
                commands are executed), and false if filename is not found or
                cannot be read.





                share|improve this answer














                . (a period) is a bash shell built-in command that executes the commands from a file passed as argument, in the current shell. 'source' is a synonym for '.'.



                From Bash man page:



                . filename [arguments]
                source filename [arguments]
                Read and execute commands from filename in the current shell
                environment and return the exit status of the last command exe‐
                cuted from filename. If filename does not contain a slash, file
                names in PATH are used to find the directory containing file‐
                name. The file searched for in PATH need not be executable.
                When bash is not in posix mode, the current directory is
                searched if no file is found in PATH. If the sourcepath option
                to the shopt builtin command is turned off, the PATH is not
                searched. If any arguments are supplied, they become the posi‐
                tional parameters when filename is executed. Otherwise the
                positional parameters are unchanged. The return status is the
                status of the last command exited within the script (0 if no
                commands are executed), and false if filename is not found or
                cannot be read.






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Sep 24 '09 at 11:47

























                answered Sep 24 '09 at 10:48









                Jawa

                3,15982435




                3,15982435






















                    up vote
                    20
                    down vote













                    'source' is the long version of '.' command. On the bash prompt one can do:



                    source ~/.bashrc


                    to reload your (changed?) bash setting for current running bash.



                    Short version would be:



                    . ~/.bashrc


                    The man page:



                    . filename [arguments]
                    source filename [arguments]
                    Read and execute commands from filename in the current shell environment and
                    return the exit status of the last command executed from filename. If
                    filename does not contain a slash, file names in PATH are used to find the
                    directory containing filename. The file searched for in PATH need not be
                    executable. When bash is not in posix mode, the current directory is
                    searched if no file is found in PATH. If the sourcepath option to the short
                    builtin command is turned off, the PATH is not searched. If any arguments
                    are supplied, they become the positional parameters when filename is
                    executed. Otherwise the positional parameters are unchanged. The return
                    status is the status of the last command exited within the script (0 if no
                    commands are executed), and false if filename is not found or cannot be
                    read.





                    share|improve this answer























                    • This should be the accepted answer.
                      – Peter Mortensen
                      Mar 19 '17 at 8:00















                    up vote
                    20
                    down vote













                    'source' is the long version of '.' command. On the bash prompt one can do:



                    source ~/.bashrc


                    to reload your (changed?) bash setting for current running bash.



                    Short version would be:



                    . ~/.bashrc


                    The man page:



                    . filename [arguments]
                    source filename [arguments]
                    Read and execute commands from filename in the current shell environment and
                    return the exit status of the last command executed from filename. If
                    filename does not contain a slash, file names in PATH are used to find the
                    directory containing filename. The file searched for in PATH need not be
                    executable. When bash is not in posix mode, the current directory is
                    searched if no file is found in PATH. If the sourcepath option to the short
                    builtin command is turned off, the PATH is not searched. If any arguments
                    are supplied, they become the positional parameters when filename is
                    executed. Otherwise the positional parameters are unchanged. The return
                    status is the status of the last command exited within the script (0 if no
                    commands are executed), and false if filename is not found or cannot be
                    read.





                    share|improve this answer























                    • This should be the accepted answer.
                      – Peter Mortensen
                      Mar 19 '17 at 8:00













                    up vote
                    20
                    down vote










                    up vote
                    20
                    down vote









                    'source' is the long version of '.' command. On the bash prompt one can do:



                    source ~/.bashrc


                    to reload your (changed?) bash setting for current running bash.



                    Short version would be:



                    . ~/.bashrc


                    The man page:



                    . filename [arguments]
                    source filename [arguments]
                    Read and execute commands from filename in the current shell environment and
                    return the exit status of the last command executed from filename. If
                    filename does not contain a slash, file names in PATH are used to find the
                    directory containing filename. The file searched for in PATH need not be
                    executable. When bash is not in posix mode, the current directory is
                    searched if no file is found in PATH. If the sourcepath option to the short
                    builtin command is turned off, the PATH is not searched. If any arguments
                    are supplied, they become the positional parameters when filename is
                    executed. Otherwise the positional parameters are unchanged. The return
                    status is the status of the last command exited within the script (0 if no
                    commands are executed), and false if filename is not found or cannot be
                    read.





                    share|improve this answer














                    'source' is the long version of '.' command. On the bash prompt one can do:



                    source ~/.bashrc


                    to reload your (changed?) bash setting for current running bash.



                    Short version would be:



                    . ~/.bashrc


                    The man page:



                    . filename [arguments]
                    source filename [arguments]
                    Read and execute commands from filename in the current shell environment and
                    return the exit status of the last command executed from filename. If
                    filename does not contain a slash, file names in PATH are used to find the
                    directory containing filename. The file searched for in PATH need not be
                    executable. When bash is not in posix mode, the current directory is
                    searched if no file is found in PATH. If the sourcepath option to the short
                    builtin command is turned off, the PATH is not searched. If any arguments
                    are supplied, they become the positional parameters when filename is
                    executed. Otherwise the positional parameters are unchanged. The return
                    status is the status of the last command exited within the script (0 if no
                    commands are executed), and false if filename is not found or cannot be
                    read.






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 10 '14 at 17:13









                    OJFord

                    3021515




                    3021515










                    answered Sep 24 '09 at 10:46









                    Joakim Elofsson

                    1,85111418




                    1,85111418












                    • This should be the accepted answer.
                      – Peter Mortensen
                      Mar 19 '17 at 8:00


















                    • This should be the accepted answer.
                      – Peter Mortensen
                      Mar 19 '17 at 8:00
















                    This should be the accepted answer.
                    – Peter Mortensen
                    Mar 19 '17 at 8:00




                    This should be the accepted answer.
                    – Peter Mortensen
                    Mar 19 '17 at 8:00










                    up vote
                    19
                    down vote













                    source command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./ executes the provided executable script in a new shell.



                    source command do have a synonym . filename.



                    To make it more clear, have a look at the following script, which sets the alias.



                    make_alias



                    #! /bin/bash

                    alias myproject='cd ~/Documents/Projects/2015/NewProject'


                    Now we have two choices to execute this script. But with only one option, the desired alias for current shell can be created among these two options.



                    Option 1: ./make_alias



                    Make script executable first.



                    chmod +x make_alias


                    Execute



                    ./make_alias


                    Verify



                    alias


                    Output



                    **nothing**


                    Whoops! Alias is gone with the new shell.



                    Let's go with the second option.



                    Option 2: source make_alias



                    Execute



                    source make_alias


                    or



                    . make_alias


                    Verify



                    alias


                    Output



                    alias myproject='cd ~/Documents/Projects/2015/NewProject'


                    Yeah Alias is set.






                    share|improve this answer

























                      up vote
                      19
                      down vote













                      source command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./ executes the provided executable script in a new shell.



                      source command do have a synonym . filename.



                      To make it more clear, have a look at the following script, which sets the alias.



                      make_alias



                      #! /bin/bash

                      alias myproject='cd ~/Documents/Projects/2015/NewProject'


                      Now we have two choices to execute this script. But with only one option, the desired alias for current shell can be created among these two options.



                      Option 1: ./make_alias



                      Make script executable first.



                      chmod +x make_alias


                      Execute



                      ./make_alias


                      Verify



                      alias


                      Output



                      **nothing**


                      Whoops! Alias is gone with the new shell.



                      Let's go with the second option.



                      Option 2: source make_alias



                      Execute



                      source make_alias


                      or



                      . make_alias


                      Verify



                      alias


                      Output



                      alias myproject='cd ~/Documents/Projects/2015/NewProject'


                      Yeah Alias is set.






                      share|improve this answer























                        up vote
                        19
                        down vote










                        up vote
                        19
                        down vote









                        source command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./ executes the provided executable script in a new shell.



                        source command do have a synonym . filename.



                        To make it more clear, have a look at the following script, which sets the alias.



                        make_alias



                        #! /bin/bash

                        alias myproject='cd ~/Documents/Projects/2015/NewProject'


                        Now we have two choices to execute this script. But with only one option, the desired alias for current shell can be created among these two options.



                        Option 1: ./make_alias



                        Make script executable first.



                        chmod +x make_alias


                        Execute



                        ./make_alias


                        Verify



                        alias


                        Output



                        **nothing**


                        Whoops! Alias is gone with the new shell.



                        Let's go with the second option.



                        Option 2: source make_alias



                        Execute



                        source make_alias


                        or



                        . make_alias


                        Verify



                        alias


                        Output



                        alias myproject='cd ~/Documents/Projects/2015/NewProject'


                        Yeah Alias is set.






                        share|improve this answer












                        source command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./ executes the provided executable script in a new shell.



                        source command do have a synonym . filename.



                        To make it more clear, have a look at the following script, which sets the alias.



                        make_alias



                        #! /bin/bash

                        alias myproject='cd ~/Documents/Projects/2015/NewProject'


                        Now we have two choices to execute this script. But with only one option, the desired alias for current shell can be created among these two options.



                        Option 1: ./make_alias



                        Make script executable first.



                        chmod +x make_alias


                        Execute



                        ./make_alias


                        Verify



                        alias


                        Output



                        **nothing**


                        Whoops! Alias is gone with the new shell.



                        Let's go with the second option.



                        Option 2: source make_alias



                        Execute



                        source make_alias


                        or



                        . make_alias


                        Verify



                        alias


                        Output



                        alias myproject='cd ~/Documents/Projects/2015/NewProject'


                        Yeah Alias is set.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 27 '15 at 13:57









                        Harsh Vakharia

                        31125




                        31125






















                            up vote
                            5
                            down vote













                            When in doubt, the best thing to do is use the info command:



                            [root@abc ~]# info source

                            BASH BUILTIN COMMANDS
                            Unless otherwise noted, each builtin command documented in this section
                            as accepting options preceded by - accepts -- to signify the end of the
                            options. The :, true, false, and test builtins do not accept options
                            and do not treat -- specially. The exit, logout, break, continue, let,
                            and shift builtins accept and process arguments beginning with - with-
                            out requiring --. Other builtins that accept arguments but are not
                            specified as accepting options interpret arguments beginning with - as
                            invalid options and require -- to prevent this interpretation.
                            : [arguments]
                            No effect; the command does nothing beyond expanding arguments
                            and performing any specified redirections. A zero exit code is
                            returned.

                            . filename [arguments]
                            source filename [arguments]
                            Read and execute commands from filename in the current shell
                            environment and return the exit status of the last command exe-
                            cuted from filename. If filename does not contain a slash, file
                            names in PATH are used to find the directory containing file-
                            name. The file searched for in PATH need not be executable.
                            When bash is not in posix mode, the current directory is
                            searched if no file is found in PATH. If the sourcepath option
                            to the shopt builtin command is turned off, the PATH is not
                            searched. If any arguments are supplied, they become the posi-
                            tional parameters when filename is executed. Otherwise the
                            positional parameters are unchanged. The return status is the
                            status of the last command exited within the script (0 if no
                            commands are executed), and false if filename is not found or
                            cannot be read.





                            share|improve this answer























                            • Could you provide more than just RTFM?
                              – Peter Mortensen
                              Mar 19 '17 at 9:04















                            up vote
                            5
                            down vote













                            When in doubt, the best thing to do is use the info command:



                            [root@abc ~]# info source

                            BASH BUILTIN COMMANDS
                            Unless otherwise noted, each builtin command documented in this section
                            as accepting options preceded by - accepts -- to signify the end of the
                            options. The :, true, false, and test builtins do not accept options
                            and do not treat -- specially. The exit, logout, break, continue, let,
                            and shift builtins accept and process arguments beginning with - with-
                            out requiring --. Other builtins that accept arguments but are not
                            specified as accepting options interpret arguments beginning with - as
                            invalid options and require -- to prevent this interpretation.
                            : [arguments]
                            No effect; the command does nothing beyond expanding arguments
                            and performing any specified redirections. A zero exit code is
                            returned.

                            . filename [arguments]
                            source filename [arguments]
                            Read and execute commands from filename in the current shell
                            environment and return the exit status of the last command exe-
                            cuted from filename. If filename does not contain a slash, file
                            names in PATH are used to find the directory containing file-
                            name. The file searched for in PATH need not be executable.
                            When bash is not in posix mode, the current directory is
                            searched if no file is found in PATH. If the sourcepath option
                            to the shopt builtin command is turned off, the PATH is not
                            searched. If any arguments are supplied, they become the posi-
                            tional parameters when filename is executed. Otherwise the
                            positional parameters are unchanged. The return status is the
                            status of the last command exited within the script (0 if no
                            commands are executed), and false if filename is not found or
                            cannot be read.





                            share|improve this answer























                            • Could you provide more than just RTFM?
                              – Peter Mortensen
                              Mar 19 '17 at 9:04













                            up vote
                            5
                            down vote










                            up vote
                            5
                            down vote









                            When in doubt, the best thing to do is use the info command:



                            [root@abc ~]# info source

                            BASH BUILTIN COMMANDS
                            Unless otherwise noted, each builtin command documented in this section
                            as accepting options preceded by - accepts -- to signify the end of the
                            options. The :, true, false, and test builtins do not accept options
                            and do not treat -- specially. The exit, logout, break, continue, let,
                            and shift builtins accept and process arguments beginning with - with-
                            out requiring --. Other builtins that accept arguments but are not
                            specified as accepting options interpret arguments beginning with - as
                            invalid options and require -- to prevent this interpretation.
                            : [arguments]
                            No effect; the command does nothing beyond expanding arguments
                            and performing any specified redirections. A zero exit code is
                            returned.

                            . filename [arguments]
                            source filename [arguments]
                            Read and execute commands from filename in the current shell
                            environment and return the exit status of the last command exe-
                            cuted from filename. If filename does not contain a slash, file
                            names in PATH are used to find the directory containing file-
                            name. The file searched for in PATH need not be executable.
                            When bash is not in posix mode, the current directory is
                            searched if no file is found in PATH. If the sourcepath option
                            to the shopt builtin command is turned off, the PATH is not
                            searched. If any arguments are supplied, they become the posi-
                            tional parameters when filename is executed. Otherwise the
                            positional parameters are unchanged. The return status is the
                            status of the last command exited within the script (0 if no
                            commands are executed), and false if filename is not found or
                            cannot be read.





                            share|improve this answer














                            When in doubt, the best thing to do is use the info command:



                            [root@abc ~]# info source

                            BASH BUILTIN COMMANDS
                            Unless otherwise noted, each builtin command documented in this section
                            as accepting options preceded by - accepts -- to signify the end of the
                            options. The :, true, false, and test builtins do not accept options
                            and do not treat -- specially. The exit, logout, break, continue, let,
                            and shift builtins accept and process arguments beginning with - with-
                            out requiring --. Other builtins that accept arguments but are not
                            specified as accepting options interpret arguments beginning with - as
                            invalid options and require -- to prevent this interpretation.
                            : [arguments]
                            No effect; the command does nothing beyond expanding arguments
                            and performing any specified redirections. A zero exit code is
                            returned.

                            . filename [arguments]
                            source filename [arguments]
                            Read and execute commands from filename in the current shell
                            environment and return the exit status of the last command exe-
                            cuted from filename. If filename does not contain a slash, file
                            names in PATH are used to find the directory containing file-
                            name. The file searched for in PATH need not be executable.
                            When bash is not in posix mode, the current directory is
                            searched if no file is found in PATH. If the sourcepath option
                            to the shopt builtin command is turned off, the PATH is not
                            searched. If any arguments are supplied, they become the posi-
                            tional parameters when filename is executed. Otherwise the
                            positional parameters are unchanged. The return status is the
                            status of the last command exited within the script (0 if no
                            commands are executed), and false if filename is not found or
                            cannot be read.






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 19 '17 at 9:03









                            Peter Mortensen

                            8,301166184




                            8,301166184










                            answered Nov 11 '15 at 5:44









                            Akshay Upadhyaya

                            6111




                            6111












                            • Could you provide more than just RTFM?
                              – Peter Mortensen
                              Mar 19 '17 at 9:04


















                            • Could you provide more than just RTFM?
                              – Peter Mortensen
                              Mar 19 '17 at 9:04
















                            Could you provide more than just RTFM?
                            – Peter Mortensen
                            Mar 19 '17 at 9:04




                            Could you provide more than just RTFM?
                            – Peter Mortensen
                            Mar 19 '17 at 9:04










                            up vote
                            3
                            down vote













                            Type the command "help source" in your shell.



                            You will get output like this:



                            source: source filename [arguments]

                            Execute commands from a file in the current shell.

                            Read and execute commands from FILENAME in the current shell. The
                            entries in $PATH are used to find the directory containing FILENAME.
                            If any ARGUMENTS are supplied, they become the positional parameters
                            when FILENAME is executed.

                            Exit Status:
                            Returns the status of the last command executed in FILENAME; fails if
                            FILENAME cannot be read.





                            share|improve this answer



























                              up vote
                              3
                              down vote













                              Type the command "help source" in your shell.



                              You will get output like this:



                              source: source filename [arguments]

                              Execute commands from a file in the current shell.

                              Read and execute commands from FILENAME in the current shell. The
                              entries in $PATH are used to find the directory containing FILENAME.
                              If any ARGUMENTS are supplied, they become the positional parameters
                              when FILENAME is executed.

                              Exit Status:
                              Returns the status of the last command executed in FILENAME; fails if
                              FILENAME cannot be read.





                              share|improve this answer

























                                up vote
                                3
                                down vote










                                up vote
                                3
                                down vote









                                Type the command "help source" in your shell.



                                You will get output like this:



                                source: source filename [arguments]

                                Execute commands from a file in the current shell.

                                Read and execute commands from FILENAME in the current shell. The
                                entries in $PATH are used to find the directory containing FILENAME.
                                If any ARGUMENTS are supplied, they become the positional parameters
                                when FILENAME is executed.

                                Exit Status:
                                Returns the status of the last command executed in FILENAME; fails if
                                FILENAME cannot be read.





                                share|improve this answer














                                Type the command "help source" in your shell.



                                You will get output like this:



                                source: source filename [arguments]

                                Execute commands from a file in the current shell.

                                Read and execute commands from FILENAME in the current shell. The
                                entries in $PATH are used to find the directory containing FILENAME.
                                If any ARGUMENTS are supplied, they become the positional parameters
                                when FILENAME is executed.

                                Exit Status:
                                Returns the status of the last command executed in FILENAME; fails if
                                FILENAME cannot be read.






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Mar 19 '17 at 8:03









                                Peter Mortensen

                                8,301166184




                                8,301166184










                                answered Sep 19 '15 at 14:14









                                Jasser

                                1315




                                1315






















                                    up vote
                                    2
                                    down vote













                                    From the Linux Documentation Project, Advanced Bash Scripting Guide,

                                    Chapter 15 - Internals Commands and Builtins:




                                    source, . (dot command):

                                    This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

                                    If the sourced file is itself an executable script, then it will run, then return control to the script that called it. A sourced executable script may use a return for this purpose.




                                    So, for those familiar with C programming language, sourcing a file has an effect similar to the #include directive.



                                    Note also that you may pass positional arguments to the file being sourced, like:



                                    $ source $filename $arg1 arg2





                                    share|improve this answer





















                                    • How does this answer differ from the 9 previous answers?
                                      – Stephen Rauch
                                      Jun 12 '17 at 0:31






                                    • 1




                                      I add another source of information and additional information not mentioned before.
                                      – Alexandro de Oliveira
                                      Jun 12 '17 at 1:16















                                    up vote
                                    2
                                    down vote













                                    From the Linux Documentation Project, Advanced Bash Scripting Guide,

                                    Chapter 15 - Internals Commands and Builtins:




                                    source, . (dot command):

                                    This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

                                    If the sourced file is itself an executable script, then it will run, then return control to the script that called it. A sourced executable script may use a return for this purpose.




                                    So, for those familiar with C programming language, sourcing a file has an effect similar to the #include directive.



                                    Note also that you may pass positional arguments to the file being sourced, like:



                                    $ source $filename $arg1 arg2





                                    share|improve this answer





















                                    • How does this answer differ from the 9 previous answers?
                                      – Stephen Rauch
                                      Jun 12 '17 at 0:31






                                    • 1




                                      I add another source of information and additional information not mentioned before.
                                      – Alexandro de Oliveira
                                      Jun 12 '17 at 1:16













                                    up vote
                                    2
                                    down vote










                                    up vote
                                    2
                                    down vote









                                    From the Linux Documentation Project, Advanced Bash Scripting Guide,

                                    Chapter 15 - Internals Commands and Builtins:




                                    source, . (dot command):

                                    This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

                                    If the sourced file is itself an executable script, then it will run, then return control to the script that called it. A sourced executable script may use a return for this purpose.




                                    So, for those familiar with C programming language, sourcing a file has an effect similar to the #include directive.



                                    Note also that you may pass positional arguments to the file being sourced, like:



                                    $ source $filename $arg1 arg2





                                    share|improve this answer












                                    From the Linux Documentation Project, Advanced Bash Scripting Guide,

                                    Chapter 15 - Internals Commands and Builtins:




                                    source, . (dot command):

                                    This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

                                    If the sourced file is itself an executable script, then it will run, then return control to the script that called it. A sourced executable script may use a return for this purpose.




                                    So, for those familiar with C programming language, sourcing a file has an effect similar to the #include directive.



                                    Note also that you may pass positional arguments to the file being sourced, like:



                                    $ source $filename $arg1 arg2






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jun 12 '17 at 0:13









                                    Alexandro de Oliveira

                                    13315




                                    13315












                                    • How does this answer differ from the 9 previous answers?
                                      – Stephen Rauch
                                      Jun 12 '17 at 0:31






                                    • 1




                                      I add another source of information and additional information not mentioned before.
                                      – Alexandro de Oliveira
                                      Jun 12 '17 at 1:16


















                                    • How does this answer differ from the 9 previous answers?
                                      – Stephen Rauch
                                      Jun 12 '17 at 0:31






                                    • 1




                                      I add another source of information and additional information not mentioned before.
                                      – Alexandro de Oliveira
                                      Jun 12 '17 at 1:16
















                                    How does this answer differ from the 9 previous answers?
                                    – Stephen Rauch
                                    Jun 12 '17 at 0:31




                                    How does this answer differ from the 9 previous answers?
                                    – Stephen Rauch
                                    Jun 12 '17 at 0:31




                                    1




                                    1




                                    I add another source of information and additional information not mentioned before.
                                    – Alexandro de Oliveira
                                    Jun 12 '17 at 1:16




                                    I add another source of information and additional information not mentioned before.
                                    – Alexandro de Oliveira
                                    Jun 12 '17 at 1:16










                                    up vote
                                    1
                                    down vote













                                    It should be noted that although being an awesome command, neither source nor its shorthand of . would source more than one file, meaning



                                    source *.sh


                                    or



                                    . script1.sh script2.sh


                                    will not work.



                                    We can fall back using for loops, but it would issue the executable many times, creating multiple commands or issue of it.



                                    Conclusion: source doesn't take multiple files as input. The argument has to be one.



                                    Which sucks IMHO.






                                    share|improve this answer



























                                      up vote
                                      1
                                      down vote













                                      It should be noted that although being an awesome command, neither source nor its shorthand of . would source more than one file, meaning



                                      source *.sh


                                      or



                                      . script1.sh script2.sh


                                      will not work.



                                      We can fall back using for loops, but it would issue the executable many times, creating multiple commands or issue of it.



                                      Conclusion: source doesn't take multiple files as input. The argument has to be one.



                                      Which sucks IMHO.






                                      share|improve this answer

























                                        up vote
                                        1
                                        down vote










                                        up vote
                                        1
                                        down vote









                                        It should be noted that although being an awesome command, neither source nor its shorthand of . would source more than one file, meaning



                                        source *.sh


                                        or



                                        . script1.sh script2.sh


                                        will not work.



                                        We can fall back using for loops, but it would issue the executable many times, creating multiple commands or issue of it.



                                        Conclusion: source doesn't take multiple files as input. The argument has to be one.



                                        Which sucks IMHO.






                                        share|improve this answer














                                        It should be noted that although being an awesome command, neither source nor its shorthand of . would source more than one file, meaning



                                        source *.sh


                                        or



                                        . script1.sh script2.sh


                                        will not work.



                                        We can fall back using for loops, but it would issue the executable many times, creating multiple commands or issue of it.



                                        Conclusion: source doesn't take multiple files as input. The argument has to be one.



                                        Which sucks IMHO.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jun 3 '17 at 5:34









                                        Peter Mortensen

                                        8,301166184




                                        8,301166184










                                        answered May 31 '17 at 11:23









                                        w17t

                                        2,23441637




                                        2,23441637






















                                            up vote
                                            0
                                            down vote













                                            With source you can pass variables or functions from another file in to your script and use them without having to write them again.



                                            F.I:



                                            #!/bin/bash

                                            source /etc/environment

                                            source /myscripts/jetty-common/config/jetty-functions.sh


                                            Cheers






                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote













                                              With source you can pass variables or functions from another file in to your script and use them without having to write them again.



                                              F.I:



                                              #!/bin/bash

                                              source /etc/environment

                                              source /myscripts/jetty-common/config/jetty-functions.sh


                                              Cheers






                                              share|improve this answer























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                With source you can pass variables or functions from another file in to your script and use them without having to write them again.



                                                F.I:



                                                #!/bin/bash

                                                source /etc/environment

                                                source /myscripts/jetty-common/config/jetty-functions.sh


                                                Cheers






                                                share|improve this answer












                                                With source you can pass variables or functions from another file in to your script and use them without having to write them again.



                                                F.I:



                                                #!/bin/bash

                                                source /etc/environment

                                                source /myscripts/jetty-common/config/jetty-functions.sh


                                                Cheers







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 28 at 8:58









                                                DimiDak

                                                1011




                                                1011






























                                                    draft saved

                                                    draft discarded




















































                                                    Thanks for contributing an answer to Super User!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.





                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                    Please pay close attention to the following guidance:


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f46139%2fwhat-does-source-do%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Mouse cursor on multiple screens with different PPI

                                                    Agildo Ribeiro

                                                    Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”