What does backslash dot mean as a command?

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
11
down vote

favorite
2












A software I installed inserted a line in my profile that reads:



[ -s "$SOME_FILE" ] && . "$SOME_FILE"


I know dot . is synonymous with source, so I suspect this is just sourcing the file, but I have never seen . before; does it do something else?



Edit, regarding DVs: searching for "backslash dot" leads to questions regarding ./ when calling executable files, and man source leads to a manpage where . does not appear. I don't know what else to try, hence the question.



Edit 2: see related questions



  • Why start a shell command with a backslash

  • Backslash at the beginning of a command

  • Why do backslashes prevent alias expansion

  • Run a command that is shadowed by an alias






share|improve this question



























    up vote
    11
    down vote

    favorite
    2












    A software I installed inserted a line in my profile that reads:



    [ -s "$SOME_FILE" ] && . "$SOME_FILE"


    I know dot . is synonymous with source, so I suspect this is just sourcing the file, but I have never seen . before; does it do something else?



    Edit, regarding DVs: searching for "backslash dot" leads to questions regarding ./ when calling executable files, and man source leads to a manpage where . does not appear. I don't know what else to try, hence the question.



    Edit 2: see related questions



    • Why start a shell command with a backslash

    • Backslash at the beginning of a command

    • Why do backslashes prevent alias expansion

    • Run a command that is shadowed by an alias






    share|improve this question























      up vote
      11
      down vote

      favorite
      2









      up vote
      11
      down vote

      favorite
      2






      2





      A software I installed inserted a line in my profile that reads:



      [ -s "$SOME_FILE" ] && . "$SOME_FILE"


      I know dot . is synonymous with source, so I suspect this is just sourcing the file, but I have never seen . before; does it do something else?



      Edit, regarding DVs: searching for "backslash dot" leads to questions regarding ./ when calling executable files, and man source leads to a manpage where . does not appear. I don't know what else to try, hence the question.



      Edit 2: see related questions



      • Why start a shell command with a backslash

      • Backslash at the beginning of a command

      • Why do backslashes prevent alias expansion

      • Run a command that is shadowed by an alias






      share|improve this question













      A software I installed inserted a line in my profile that reads:



      [ -s "$SOME_FILE" ] && . "$SOME_FILE"


      I know dot . is synonymous with source, so I suspect this is just sourcing the file, but I have never seen . before; does it do something else?



      Edit, regarding DVs: searching for "backslash dot" leads to questions regarding ./ when calling executable files, and man source leads to a manpage where . does not appear. I don't know what else to try, hence the question.



      Edit 2: see related questions



      • Why start a shell command with a backslash

      • Backslash at the beginning of a command

      • Why do backslashes prevent alias expansion

      • Run a command that is shadowed by an alias








      share|improve this question












      share|improve this question




      share|improve this question








      edited 22 hours ago









      psmears

      43328




      43328









      asked yesterday









      Sheljohn

      5113519




      5113519




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          23
          down vote



          accepted










          A backslash outside of quotes means “interpret the next character literally during parsing”. Since . is an ordinary character for the parser, . is parsed in the same way as ., and invokes the builtin . (of which source is a synonym in bash).



          There is one case where it could make a difference in this context. If a user has defined an alias called . earlier in .profile, and .profile is being read in a shell that expands aliases (which bash only does by default when it's invoked interactively), then . would trigger the alias, but . would still trigger the builtin, because the shell doesn't try alias expansion on words that were quoted in any way.



          I suspect that . was changed to . because a user complained after they'd made an alias for ..



          Note that . would invoke a function called .. Presumably users who write functions are more knowledgeable than users who write aliases and would know that redefining a standard command in .profile is a bad idea if you're going to include code from third parties. But if you wanted to bypass both aliases and functions, you could write command .. The author of this snippet didn't do this either because they cared about antique shells that didn't have the command builtin, or more likely because they weren't aware of it.



          By the way, defining any alias in .profile is a bad idea because .profile is a session initialization script, not a shell initialization script. Aliases for bash belong in .bashrc.






          share|improve this answer






























            up vote
            7
            down vote













            The . is a "literal dot", i.e. just a dot. It will be taken as the standard . command (similar to source in bash).



            The POSIX standard has this to say about this (my emphasis)




            A <backslash> that is not quoted shall preserve the literal value of the following character, with the exception of a <newline>. If a <newline> follows the <backslash>, the shell shall interpret this as line continuation. The <backslash> and <newline> shall be removed before splitting the input into tokens. Since the escaped <newline> is removed entirely from the input and is not replaced by any white space, it cannot serve as a token separator.




            The dot character can be aliased:



            $ alias .='echo hello'
            $ .
            hello


            which means that . would avoid using the aliased version of the . command, because,




            After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name.







            share|improve this answer























            • I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
              – Sheljohn
              yesterday







            • 1




              @Sheljohn See updated answer.
              – Kusalananda
              yesterday










            Your Answer







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

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

            else
            createEditor();

            );

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



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460533%2fwhat-does-backslash-dot-mean-as-a-command%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            23
            down vote



            accepted










            A backslash outside of quotes means “interpret the next character literally during parsing”. Since . is an ordinary character for the parser, . is parsed in the same way as ., and invokes the builtin . (of which source is a synonym in bash).



            There is one case where it could make a difference in this context. If a user has defined an alias called . earlier in .profile, and .profile is being read in a shell that expands aliases (which bash only does by default when it's invoked interactively), then . would trigger the alias, but . would still trigger the builtin, because the shell doesn't try alias expansion on words that were quoted in any way.



            I suspect that . was changed to . because a user complained after they'd made an alias for ..



            Note that . would invoke a function called .. Presumably users who write functions are more knowledgeable than users who write aliases and would know that redefining a standard command in .profile is a bad idea if you're going to include code from third parties. But if you wanted to bypass both aliases and functions, you could write command .. The author of this snippet didn't do this either because they cared about antique shells that didn't have the command builtin, or more likely because they weren't aware of it.



            By the way, defining any alias in .profile is a bad idea because .profile is a session initialization script, not a shell initialization script. Aliases for bash belong in .bashrc.






            share|improve this answer



























              up vote
              23
              down vote



              accepted










              A backslash outside of quotes means “interpret the next character literally during parsing”. Since . is an ordinary character for the parser, . is parsed in the same way as ., and invokes the builtin . (of which source is a synonym in bash).



              There is one case where it could make a difference in this context. If a user has defined an alias called . earlier in .profile, and .profile is being read in a shell that expands aliases (which bash only does by default when it's invoked interactively), then . would trigger the alias, but . would still trigger the builtin, because the shell doesn't try alias expansion on words that were quoted in any way.



              I suspect that . was changed to . because a user complained after they'd made an alias for ..



              Note that . would invoke a function called .. Presumably users who write functions are more knowledgeable than users who write aliases and would know that redefining a standard command in .profile is a bad idea if you're going to include code from third parties. But if you wanted to bypass both aliases and functions, you could write command .. The author of this snippet didn't do this either because they cared about antique shells that didn't have the command builtin, or more likely because they weren't aware of it.



              By the way, defining any alias in .profile is a bad idea because .profile is a session initialization script, not a shell initialization script. Aliases for bash belong in .bashrc.






              share|improve this answer

























                up vote
                23
                down vote



                accepted







                up vote
                23
                down vote



                accepted






                A backslash outside of quotes means “interpret the next character literally during parsing”. Since . is an ordinary character for the parser, . is parsed in the same way as ., and invokes the builtin . (of which source is a synonym in bash).



                There is one case where it could make a difference in this context. If a user has defined an alias called . earlier in .profile, and .profile is being read in a shell that expands aliases (which bash only does by default when it's invoked interactively), then . would trigger the alias, but . would still trigger the builtin, because the shell doesn't try alias expansion on words that were quoted in any way.



                I suspect that . was changed to . because a user complained after they'd made an alias for ..



                Note that . would invoke a function called .. Presumably users who write functions are more knowledgeable than users who write aliases and would know that redefining a standard command in .profile is a bad idea if you're going to include code from third parties. But if you wanted to bypass both aliases and functions, you could write command .. The author of this snippet didn't do this either because they cared about antique shells that didn't have the command builtin, or more likely because they weren't aware of it.



                By the way, defining any alias in .profile is a bad idea because .profile is a session initialization script, not a shell initialization script. Aliases for bash belong in .bashrc.






                share|improve this answer















                A backslash outside of quotes means “interpret the next character literally during parsing”. Since . is an ordinary character for the parser, . is parsed in the same way as ., and invokes the builtin . (of which source is a synonym in bash).



                There is one case where it could make a difference in this context. If a user has defined an alias called . earlier in .profile, and .profile is being read in a shell that expands aliases (which bash only does by default when it's invoked interactively), then . would trigger the alias, but . would still trigger the builtin, because the shell doesn't try alias expansion on words that were quoted in any way.



                I suspect that . was changed to . because a user complained after they'd made an alias for ..



                Note that . would invoke a function called .. Presumably users who write functions are more knowledgeable than users who write aliases and would know that redefining a standard command in .profile is a bad idea if you're going to include code from third parties. But if you wanted to bypass both aliases and functions, you could write command .. The author of this snippet didn't do this either because they cared about antique shells that didn't have the command builtin, or more likely because they weren't aware of it.



                By the way, defining any alias in .profile is a bad idea because .profile is a session initialization script, not a shell initialization script. Aliases for bash belong in .bashrc.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited yesterday


























                answered yesterday









                Gilles

                501k1169851510




                501k1169851510






















                    up vote
                    7
                    down vote













                    The . is a "literal dot", i.e. just a dot. It will be taken as the standard . command (similar to source in bash).



                    The POSIX standard has this to say about this (my emphasis)




                    A <backslash> that is not quoted shall preserve the literal value of the following character, with the exception of a <newline>. If a <newline> follows the <backslash>, the shell shall interpret this as line continuation. The <backslash> and <newline> shall be removed before splitting the input into tokens. Since the escaped <newline> is removed entirely from the input and is not replaced by any white space, it cannot serve as a token separator.




                    The dot character can be aliased:



                    $ alias .='echo hello'
                    $ .
                    hello


                    which means that . would avoid using the aliased version of the . command, because,




                    After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name.







                    share|improve this answer























                    • I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
                      – Sheljohn
                      yesterday







                    • 1




                      @Sheljohn See updated answer.
                      – Kusalananda
                      yesterday














                    up vote
                    7
                    down vote













                    The . is a "literal dot", i.e. just a dot. It will be taken as the standard . command (similar to source in bash).



                    The POSIX standard has this to say about this (my emphasis)




                    A <backslash> that is not quoted shall preserve the literal value of the following character, with the exception of a <newline>. If a <newline> follows the <backslash>, the shell shall interpret this as line continuation. The <backslash> and <newline> shall be removed before splitting the input into tokens. Since the escaped <newline> is removed entirely from the input and is not replaced by any white space, it cannot serve as a token separator.




                    The dot character can be aliased:



                    $ alias .='echo hello'
                    $ .
                    hello


                    which means that . would avoid using the aliased version of the . command, because,




                    After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name.







                    share|improve this answer























                    • I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
                      – Sheljohn
                      yesterday







                    • 1




                      @Sheljohn See updated answer.
                      – Kusalananda
                      yesterday












                    up vote
                    7
                    down vote










                    up vote
                    7
                    down vote









                    The . is a "literal dot", i.e. just a dot. It will be taken as the standard . command (similar to source in bash).



                    The POSIX standard has this to say about this (my emphasis)




                    A <backslash> that is not quoted shall preserve the literal value of the following character, with the exception of a <newline>. If a <newline> follows the <backslash>, the shell shall interpret this as line continuation. The <backslash> and <newline> shall be removed before splitting the input into tokens. Since the escaped <newline> is removed entirely from the input and is not replaced by any white space, it cannot serve as a token separator.




                    The dot character can be aliased:



                    $ alias .='echo hello'
                    $ .
                    hello


                    which means that . would avoid using the aliased version of the . command, because,




                    After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name.







                    share|improve this answer















                    The . is a "literal dot", i.e. just a dot. It will be taken as the standard . command (similar to source in bash).



                    The POSIX standard has this to say about this (my emphasis)




                    A <backslash> that is not quoted shall preserve the literal value of the following character, with the exception of a <newline>. If a <newline> follows the <backslash>, the shell shall interpret this as line continuation. The <backslash> and <newline> shall be removed before splitting the input into tokens. Since the escaped <newline> is removed entirely from the input and is not replaced by any white space, it cannot serve as a token separator.




                    The dot character can be aliased:



                    $ alias .='echo hello'
                    $ .
                    hello


                    which means that . would avoid using the aliased version of the . command, because,




                    After a token has been delimited, but before applying the grammatical rules in Shell Grammar, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name.








                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited yesterday


























                    answered yesterday









                    Kusalananda

                    100k13199310




                    100k13199310











                    • I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
                      – Sheljohn
                      yesterday







                    • 1




                      @Sheljohn See updated answer.
                      – Kusalananda
                      yesterday
















                    • I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
                      – Sheljohn
                      yesterday







                    • 1




                      @Sheljohn See updated answer.
                      – Kusalananda
                      yesterday















                    I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
                    – Sheljohn
                    yesterday





                    I was looking for official source about how backslash in a word is interpreted as quoting, and how this prevents alias expansion. Thanks for the reference!
                    – Sheljohn
                    yesterday





                    1




                    1




                    @Sheljohn See updated answer.
                    – Kusalananda
                    yesterday




                    @Sheljohn See updated answer.
                    – Kusalananda
                    yesterday












                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460533%2fwhat-does-backslash-dot-mean-as-a-command%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What is the equation of a 3D cone with generalised tilt?

                    Relationship between determinant of matrix and determinant of adjoint?

                    Color the edges and diagonals of a regular polygon