Should the last line in a configuration file have a newline after it?











up vote
2
down vote

favorite












I sometimes whether I should put a newline after the last line in a configuration file, especially if it is a one-line configuration file, like the hostname file.



Does it not matter, or is there a rule?










share|improve this question






















  • It's useful if you want to append to it.
    – Ben
    Nov 29 at 0:55












  • See unix.stackexchange.com/q/18743/185953
    – Ben
    Nov 29 at 0:57










  • it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
    – jsotola
    Nov 30 at 2:48















up vote
2
down vote

favorite












I sometimes whether I should put a newline after the last line in a configuration file, especially if it is a one-line configuration file, like the hostname file.



Does it not matter, or is there a rule?










share|improve this question






















  • It's useful if you want to append to it.
    – Ben
    Nov 29 at 0:55












  • See unix.stackexchange.com/q/18743/185953
    – Ben
    Nov 29 at 0:57










  • it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
    – jsotola
    Nov 30 at 2:48













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I sometimes whether I should put a newline after the last line in a configuration file, especially if it is a one-line configuration file, like the hostname file.



Does it not matter, or is there a rule?










share|improve this question













I sometimes whether I should put a newline after the last line in a configuration file, especially if it is a one-line configuration file, like the hostname file.



Does it not matter, or is there a rule?







configuration






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 29 at 0:50









Tyler Durden

1,52841849




1,52841849












  • It's useful if you want to append to it.
    – Ben
    Nov 29 at 0:55












  • See unix.stackexchange.com/q/18743/185953
    – Ben
    Nov 29 at 0:57










  • it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
    – jsotola
    Nov 30 at 2:48


















  • It's useful if you want to append to it.
    – Ben
    Nov 29 at 0:55












  • See unix.stackexchange.com/q/18743/185953
    – Ben
    Nov 29 at 0:57










  • it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
    – jsotola
    Nov 30 at 2:48
















It's useful if you want to append to it.
– Ben
Nov 29 at 0:55






It's useful if you want to append to it.
– Ben
Nov 29 at 0:55














See unix.stackexchange.com/q/18743/185953
– Ben
Nov 29 at 0:57




See unix.stackexchange.com/q/18743/185953
– Ben
Nov 29 at 0:57












it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
– jsotola
Nov 30 at 2:48




it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
– jsotola
Nov 30 at 2:48










1 Answer
1






active

oldest

votes

















up vote
7
down vote













Yes, the last character of a valid POSIX text file must be a newline.

It has been debated before.

It is easy (and very fast) to correct a file (if needed).

And vim might be configured to automatically ensure that a trail newline is included.



It matters in the sense that some tools expect a text file, and therefore expect an ending newline. For example the shell read will fail (unless configured in a special way) to read the last line of a text file that is missing a newline. And concatenation of files with cat will also require special handling.



You can not follow the recomendations to reduce one byte per file, but at the cost of added complexities to process files. It is not worth the trouble IMO.



I can not think of any other reason to avoid having an ending newline for a text file.






share|improve this answer





















    Your Answer








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

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

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f484802%2fshould-the-last-line-in-a-configuration-file-have-a-newline-after-it%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    7
    down vote













    Yes, the last character of a valid POSIX text file must be a newline.

    It has been debated before.

    It is easy (and very fast) to correct a file (if needed).

    And vim might be configured to automatically ensure that a trail newline is included.



    It matters in the sense that some tools expect a text file, and therefore expect an ending newline. For example the shell read will fail (unless configured in a special way) to read the last line of a text file that is missing a newline. And concatenation of files with cat will also require special handling.



    You can not follow the recomendations to reduce one byte per file, but at the cost of added complexities to process files. It is not worth the trouble IMO.



    I can not think of any other reason to avoid having an ending newline for a text file.






    share|improve this answer

























      up vote
      7
      down vote













      Yes, the last character of a valid POSIX text file must be a newline.

      It has been debated before.

      It is easy (and very fast) to correct a file (if needed).

      And vim might be configured to automatically ensure that a trail newline is included.



      It matters in the sense that some tools expect a text file, and therefore expect an ending newline. For example the shell read will fail (unless configured in a special way) to read the last line of a text file that is missing a newline. And concatenation of files with cat will also require special handling.



      You can not follow the recomendations to reduce one byte per file, but at the cost of added complexities to process files. It is not worth the trouble IMO.



      I can not think of any other reason to avoid having an ending newline for a text file.






      share|improve this answer























        up vote
        7
        down vote










        up vote
        7
        down vote









        Yes, the last character of a valid POSIX text file must be a newline.

        It has been debated before.

        It is easy (and very fast) to correct a file (if needed).

        And vim might be configured to automatically ensure that a trail newline is included.



        It matters in the sense that some tools expect a text file, and therefore expect an ending newline. For example the shell read will fail (unless configured in a special way) to read the last line of a text file that is missing a newline. And concatenation of files with cat will also require special handling.



        You can not follow the recomendations to reduce one byte per file, but at the cost of added complexities to process files. It is not worth the trouble IMO.



        I can not think of any other reason to avoid having an ending newline for a text file.






        share|improve this answer












        Yes, the last character of a valid POSIX text file must be a newline.

        It has been debated before.

        It is easy (and very fast) to correct a file (if needed).

        And vim might be configured to automatically ensure that a trail newline is included.



        It matters in the sense that some tools expect a text file, and therefore expect an ending newline. For example the shell read will fail (unless configured in a special way) to read the last line of a text file that is missing a newline. And concatenation of files with cat will also require special handling.



        You can not follow the recomendations to reduce one byte per file, but at the cost of added complexities to process files. It is not worth the trouble IMO.



        I can not think of any other reason to avoid having an ending newline for a text file.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 at 4:05









        Isaac

        10.1k11445




        10.1k11445






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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%2funix.stackexchange.com%2fquestions%2f484802%2fshould-the-last-line-in-a-configuration-file-have-a-newline-after-it%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

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt