Dash, command substitution not inserting newline?

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








up vote
1
down vote

favorite












Basically, this is the issue:



$ echo Hello"$(printf 'n')"World
HelloWorld


What did I overlook ?







share|improve this question























    up vote
    1
    down vote

    favorite












    Basically, this is the issue:



    $ echo Hello"$(printf 'n')"World
    HelloWorld


    What did I overlook ?







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Basically, this is the issue:



      $ echo Hello"$(printf 'n')"World
      HelloWorld


      What did I overlook ?







      share|improve this question











      Basically, this is the issue:



      $ echo Hello"$(printf 'n')"World
      HelloWorld


      What did I overlook ?









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 4 at 23:27









      Sergiy Kolodyazhnyy

      63.8k9127273




      63.8k9127273




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          This behavior is actually part of the POSIX specification for command substitution:




          The shell shall expand the command substitution by executing command
          in a subshell environment (see Shell Execution Environment) and
          replacing the command substitution (the text of command plus the
          enclosing "$()" or backquotes) with the standard output of the
          command, removing sequences of one or more characters at the
          end of the substitution
          . Embedded characters before the end
          of the output shall not be removed; however, they may be treated as
          field delimiters and eliminated during field splitting, depending on
          the value of IFS and quoting that is in effect. If the output contains
          any null bytes, the behavior is unspecified.




          So the normal quoting rule "$(...)" only preserves non-trailing newlines.



          Some suggestions for preserving trailing newlines are given in shell: keep trailing newlines ('n') in command substitution



          See also When printing a variable that contains newlines, why is the last newline stripped? for discussion of the rationale behind the specification.






          share|improve this answer





















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1043650%2fdash-command-substitution-not-inserting-newline%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            This behavior is actually part of the POSIX specification for command substitution:




            The shell shall expand the command substitution by executing command
            in a subshell environment (see Shell Execution Environment) and
            replacing the command substitution (the text of command plus the
            enclosing "$()" or backquotes) with the standard output of the
            command, removing sequences of one or more characters at the
            end of the substitution
            . Embedded characters before the end
            of the output shall not be removed; however, they may be treated as
            field delimiters and eliminated during field splitting, depending on
            the value of IFS and quoting that is in effect. If the output contains
            any null bytes, the behavior is unspecified.




            So the normal quoting rule "$(...)" only preserves non-trailing newlines.



            Some suggestions for preserving trailing newlines are given in shell: keep trailing newlines ('n') in command substitution



            See also When printing a variable that contains newlines, why is the last newline stripped? for discussion of the rationale behind the specification.






            share|improve this answer

























              up vote
              2
              down vote



              accepted










              This behavior is actually part of the POSIX specification for command substitution:




              The shell shall expand the command substitution by executing command
              in a subshell environment (see Shell Execution Environment) and
              replacing the command substitution (the text of command plus the
              enclosing "$()" or backquotes) with the standard output of the
              command, removing sequences of one or more characters at the
              end of the substitution
              . Embedded characters before the end
              of the output shall not be removed; however, they may be treated as
              field delimiters and eliminated during field splitting, depending on
              the value of IFS and quoting that is in effect. If the output contains
              any null bytes, the behavior is unspecified.




              So the normal quoting rule "$(...)" only preserves non-trailing newlines.



              Some suggestions for preserving trailing newlines are given in shell: keep trailing newlines ('n') in command substitution



              See also When printing a variable that contains newlines, why is the last newline stripped? for discussion of the rationale behind the specification.






              share|improve this answer























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                This behavior is actually part of the POSIX specification for command substitution:




                The shell shall expand the command substitution by executing command
                in a subshell environment (see Shell Execution Environment) and
                replacing the command substitution (the text of command plus the
                enclosing "$()" or backquotes) with the standard output of the
                command, removing sequences of one or more characters at the
                end of the substitution
                . Embedded characters before the end
                of the output shall not be removed; however, they may be treated as
                field delimiters and eliminated during field splitting, depending on
                the value of IFS and quoting that is in effect. If the output contains
                any null bytes, the behavior is unspecified.




                So the normal quoting rule "$(...)" only preserves non-trailing newlines.



                Some suggestions for preserving trailing newlines are given in shell: keep trailing newlines ('n') in command substitution



                See also When printing a variable that contains newlines, why is the last newline stripped? for discussion of the rationale behind the specification.






                share|improve this answer













                This behavior is actually part of the POSIX specification for command substitution:




                The shell shall expand the command substitution by executing command
                in a subshell environment (see Shell Execution Environment) and
                replacing the command substitution (the text of command plus the
                enclosing "$()" or backquotes) with the standard output of the
                command, removing sequences of one or more characters at the
                end of the substitution
                . Embedded characters before the end
                of the output shall not be removed; however, they may be treated as
                field delimiters and eliminated during field splitting, depending on
                the value of IFS and quoting that is in effect. If the output contains
                any null bytes, the behavior is unspecified.




                So the normal quoting rule "$(...)" only preserves non-trailing newlines.



                Some suggestions for preserving trailing newlines are given in shell: keep trailing newlines ('n') in command substitution



                See also When printing a variable that contains newlines, why is the last newline stripped? for discussion of the rationale behind the specification.







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jun 4 at 23:43









                steeldriver

                62k1196163




                62k1196163






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1043650%2fdash-command-substitution-not-inserting-newline%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    pylint3 and pip3 broken

                    Missing snmpget and snmpwalk

                    How to enroll fingerprints to Ubuntu 17.10 with VFS491