Next command output on the same line? Bash scriptSet bash script output to the line that called bash scriptprint the output of 2 commands in 1 file on the same lineBash: How do I make a command line call a script and pass two strings?How use an if statement to change the output messagereformatting command output within bash scriptBash print current line, line's output, and linebreak to filegrep script - output lines at the same time into echofind command not giving any outputvariable content is different than the output of the assigned commandHow to get du -ksh working without a carriage return in shell-scripting?

How did the SysRq key get onto modern keyboards if it's rarely used?

If you inherit a Roth 401(k), is it taxed?

My employer is refusing to give me the pay that was advertised after an internal job move

Golden Guardian removed before death related trigger

What language is Raven using for her attack in the new 52?

Is SecureRandom.ints() secure?

Would people understand me speaking German all over Europe?

Should I let a company know I've reverse engineered and rebuilt their app?

Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?

Exploiting the delay when a festival ticket is scanned

Can you ask a bank to delete all your personal info they might still have from any closed accounts?

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

Nuclear breeder/reactor plant controlled by two A.I. makes too much power

Why tantalum for the Hayabusa bullets?

How to store my pliers and wire cutters on my desk?

Blank spaces in a font

Can a US President, after impeachment and removal, be re-elected or re-appointed?

Should I accept an invitation to give a talk from someone who might review my proposal?

Is it okay for me to decline a project on ethical grounds?

How well would the Moon protect the Earth from an Asteroid?

Why would anyone ever invest in a cash-only etf?

Does dual boot harm a laptop battery or reduce its life?

Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?



Next command output on the same line? Bash script


Set bash script output to the line that called bash scriptprint the output of 2 commands in 1 file on the same lineBash: How do I make a command line call a script and pass two strings?How use an if statement to change the output messagereformatting command output within bash scriptBash print current line, line's output, and linebreak to filegrep script - output lines at the same time into echofind command not giving any outputvariable content is different than the output of the assigned commandHow to get du -ksh working without a carriage return in shell-scripting?






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








2















I have the following simple script:



echo "-------------------------- SOA --------------------------------"
echo " "
echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'


The output is something like this:



-------------------------- SOA --------------------------------

---------> 2019072905


Now my question is can I make an "echo" command after the dig and the output to be something like this:



-------------------------- SOA -----------------------------

---------> 2019072905 <-------------


I have tried to search for similar cases but was not able to find any related.



Would this be possible?



Thanks in advance.










share|improve this question






























    2















    I have the following simple script:



    echo "-------------------------- SOA --------------------------------"
    echo " "
    echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'


    The output is something like this:



    -------------------------- SOA --------------------------------

    ---------> 2019072905


    Now my question is can I make an "echo" command after the dig and the output to be something like this:



    -------------------------- SOA -----------------------------

    ---------> 2019072905 <-------------


    I have tried to search for similar cases but was not able to find any related.



    Would this be possible?



    Thanks in advance.










    share|improve this question


























      2












      2








      2








      I have the following simple script:



      echo "-------------------------- SOA --------------------------------"
      echo " "
      echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'


      The output is something like this:



      -------------------------- SOA --------------------------------

      ---------> 2019072905


      Now my question is can I make an "echo" command after the dig and the output to be something like this:



      -------------------------- SOA -----------------------------

      ---------> 2019072905 <-------------


      I have tried to search for similar cases but was not able to find any related.



      Would this be possible?



      Thanks in advance.










      share|improve this question














      I have the following simple script:



      echo "-------------------------- SOA --------------------------------"
      echo " "
      echo -n " ---------> "; dig soa "$1" +short | awk 'print $3'


      The output is something like this:



      -------------------------- SOA --------------------------------

      ---------> 2019072905


      Now my question is can I make an "echo" command after the dig and the output to be something like this:



      -------------------------- SOA -----------------------------

      ---------> 2019072905 <-------------


      I have tried to search for similar cases but was not able to find any related.



      Would this be possible?



      Thanks in advance.







      bash shell-script echo output






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 hours ago









      MiroMiro

      273 bronze badges




      273 bronze badges























          3 Answers
          3






          active

          oldest

          votes


















          3














          I would do the whole thing in printf instead:





          #!/bin/sh

          header='-------------------------- SOA --------------------------'

          headerLength=$(awk 'print length()' <<<"$header")

          value=$(dig soa "$1" +short | awk 'print $3')

          valueString="-----------> $value <-------------"

          valueLength=$(awk 'print length()' <<<"$valueString")

          offset=$(((headerLength + valueLength)/2+1))

          printf "%snn%$offsetsn" "$header" "$valueString"


          This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):



          $ foo.sh 2019072905
          -------------------------- SOA --------------------------------

          -----------> 2019072905 <-------------
          $ foo.sh "some random long string"
          -------------------------- SOA --------------------------------

          -----------> some random long string <-------------
          $ foo.sh "foo"
          -------------------------- SOA --------------------------

          -----------> foo <-------------





          share|improve this answer

























          • Thanks for your advice. Will check this out with 'printf' also.

            – Miro
            10 hours ago


















          2














          #!/bin/sh

          soa=$(dig soa "$1" +short | awk 'print $3')

          cat <<__EOF__
          -------------------------- SOA -----------------------------

          ---------> $soa <-------------
          __EOF__



          BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.



          I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.






          share|improve this answer



























          • Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

            – Miro
            10 hours ago











          • that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

            – cas
            10 hours ago



















          1














          cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)

          echo "-------------------------- SOA --------------------------------"
          echo " "
          echo -n " ---------> ";echo $cmd





          share|improve this answer

























          • Thanks. This is indeed something that I was looking for.

            – Miro
            10 hours ago













          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',
          autoActivateHeartbeat: false,
          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%2f532938%2fnext-command-output-on-the-same-line-bash-script%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          I would do the whole thing in printf instead:





          #!/bin/sh

          header='-------------------------- SOA --------------------------'

          headerLength=$(awk 'print length()' <<<"$header")

          value=$(dig soa "$1" +short | awk 'print $3')

          valueString="-----------> $value <-------------"

          valueLength=$(awk 'print length()' <<<"$valueString")

          offset=$(((headerLength + valueLength)/2+1))

          printf "%snn%$offsetsn" "$header" "$valueString"


          This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):



          $ foo.sh 2019072905
          -------------------------- SOA --------------------------------

          -----------> 2019072905 <-------------
          $ foo.sh "some random long string"
          -------------------------- SOA --------------------------------

          -----------> some random long string <-------------
          $ foo.sh "foo"
          -------------------------- SOA --------------------------

          -----------> foo <-------------





          share|improve this answer

























          • Thanks for your advice. Will check this out with 'printf' also.

            – Miro
            10 hours ago















          3














          I would do the whole thing in printf instead:





          #!/bin/sh

          header='-------------------------- SOA --------------------------'

          headerLength=$(awk 'print length()' <<<"$header")

          value=$(dig soa "$1" +short | awk 'print $3')

          valueString="-----------> $value <-------------"

          valueLength=$(awk 'print length()' <<<"$valueString")

          offset=$(((headerLength + valueLength)/2+1))

          printf "%snn%$offsetsn" "$header" "$valueString"


          This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):



          $ foo.sh 2019072905
          -------------------------- SOA --------------------------------

          -----------> 2019072905 <-------------
          $ foo.sh "some random long string"
          -------------------------- SOA --------------------------------

          -----------> some random long string <-------------
          $ foo.sh "foo"
          -------------------------- SOA --------------------------

          -----------> foo <-------------





          share|improve this answer

























          • Thanks for your advice. Will check this out with 'printf' also.

            – Miro
            10 hours ago













          3












          3








          3







          I would do the whole thing in printf instead:





          #!/bin/sh

          header='-------------------------- SOA --------------------------'

          headerLength=$(awk 'print length()' <<<"$header")

          value=$(dig soa "$1" +short | awk 'print $3')

          valueString="-----------> $value <-------------"

          valueLength=$(awk 'print length()' <<<"$valueString")

          offset=$(((headerLength + valueLength)/2+1))

          printf "%snn%$offsetsn" "$header" "$valueString"


          This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):



          $ foo.sh 2019072905
          -------------------------- SOA --------------------------------

          -----------> 2019072905 <-------------
          $ foo.sh "some random long string"
          -------------------------- SOA --------------------------------

          -----------> some random long string <-------------
          $ foo.sh "foo"
          -------------------------- SOA --------------------------

          -----------> foo <-------------





          share|improve this answer













          I would do the whole thing in printf instead:





          #!/bin/sh

          header='-------------------------- SOA --------------------------'

          headerLength=$(awk 'print length()' <<<"$header")

          value=$(dig soa "$1" +short | awk 'print $3')

          valueString="-----------> $value <-------------"

          valueLength=$(awk 'print length()' <<<"$valueString")

          offset=$(((headerLength + valueLength)/2+1))

          printf "%snn%$offsetsn" "$header" "$valueString"


          This has the advantage of always appearing centered no matter what the length of your value is (using a slightly modified version that just sets value=$1 to illustrate):



          $ foo.sh 2019072905
          -------------------------- SOA --------------------------------

          -----------> 2019072905 <-------------
          $ foo.sh "some random long string"
          -------------------------- SOA --------------------------------

          -----------> some random long string <-------------
          $ foo.sh "foo"
          -------------------------- SOA --------------------------

          -----------> foo <-------------






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 10 hours ago









          terdonterdon

          139k33 gold badges286 silver badges463 bronze badges




          139k33 gold badges286 silver badges463 bronze badges















          • Thanks for your advice. Will check this out with 'printf' also.

            – Miro
            10 hours ago

















          • Thanks for your advice. Will check this out with 'printf' also.

            – Miro
            10 hours ago
















          Thanks for your advice. Will check this out with 'printf' also.

          – Miro
          10 hours ago





          Thanks for your advice. Will check this out with 'printf' also.

          – Miro
          10 hours ago













          2














          #!/bin/sh

          soa=$(dig soa "$1" +short | awk 'print $3')

          cat <<__EOF__
          -------------------------- SOA -----------------------------

          ---------> $soa <-------------
          __EOF__



          BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.



          I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.






          share|improve this answer



























          • Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

            – Miro
            10 hours ago











          • that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

            – cas
            10 hours ago
















          2














          #!/bin/sh

          soa=$(dig soa "$1" +short | awk 'print $3')

          cat <<__EOF__
          -------------------------- SOA -----------------------------

          ---------> $soa <-------------
          __EOF__



          BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.



          I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.






          share|improve this answer



























          • Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

            – Miro
            10 hours ago











          • that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

            – cas
            10 hours ago














          2












          2








          2







          #!/bin/sh

          soa=$(dig soa "$1" +short | awk 'print $3')

          cat <<__EOF__
          -------------------------- SOA -----------------------------

          ---------> $soa <-------------
          __EOF__



          BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.



          I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.






          share|improve this answer















          #!/bin/sh

          soa=$(dig soa "$1" +short | awk 'print $3')

          cat <<__EOF__
          -------------------------- SOA -----------------------------

          ---------> $soa <-------------
          __EOF__



          BTW, I think the question is wrong-headed because printing all that header garbage around the SOA just makes it pointlessly harder to use the output of this script as input to another script...and even when you don't currently think you'll ever need to do that, in future you might. Verbosity in output is a "sin" in unix :) - when writing a script, you should always be thinking that your output could end up being someone else's (including yourself) input.



          I would have ignored the question, but I disliked the other answer even more. If you're going to do something wrong, you may as well do it properly.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 10 hours ago

























          answered 11 hours ago









          cascas

          40.9k4 gold badges58 silver badges109 bronze badges




          40.9k4 gold badges58 silver badges109 bronze badges















          • Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

            – Miro
            10 hours ago











          • that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

            – cas
            10 hours ago


















          • Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

            – Miro
            10 hours ago











          • that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

            – cas
            10 hours ago

















          Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

          – Miro
          10 hours ago





          Thank you for your advice. Will have this in mind. Atm, this is only for personal use combining several commands in a small script.

          – Miro
          10 hours ago













          that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

          – cas
          10 hours ago






          that's cool. i have no objection to you doing whatever you want for your own needs or education....but that answer combining the output of dig ... |awk ... with the echo statement just irked me. it's bad coding style and it's teaching bad habits.

          – cas
          10 hours ago












          1














          cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)

          echo "-------------------------- SOA --------------------------------"
          echo " "
          echo -n " ---------> ";echo $cmd





          share|improve this answer

























          • Thanks. This is indeed something that I was looking for.

            – Miro
            10 hours ago















          1














          cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)

          echo "-------------------------- SOA --------------------------------"
          echo " "
          echo -n " ---------> ";echo $cmd





          share|improve this answer

























          • Thanks. This is indeed something that I was looking for.

            – Miro
            10 hours ago













          1












          1








          1







          cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)

          echo "-------------------------- SOA --------------------------------"
          echo " "
          echo -n " ---------> ";echo $cmd





          share|improve this answer













          cmd=$(dig soa "$1" +short | awk 'print $3'; echo -n <----------;)

          echo "-------------------------- SOA --------------------------------"
          echo " "
          echo -n " ---------> ";echo $cmd






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 11 hours ago









          Rasool ZiafatyRasool Ziafaty

          1149 bronze badges




          1149 bronze badges















          • Thanks. This is indeed something that I was looking for.

            – Miro
            10 hours ago

















          • Thanks. This is indeed something that I was looking for.

            – Miro
            10 hours ago
















          Thanks. This is indeed something that I was looking for.

          – Miro
          10 hours ago





          Thanks. This is indeed something that I was looking for.

          – Miro
          10 hours ago

















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f532938%2fnext-command-output-on-the-same-line-bash-script%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

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480