Capture git output into variableInterpret backspaces in fileHow bash treats “> >()”Pipe ssh's...

My ID is expired, can I fly to the Bahamas with my passport

If an enemy is just below a 10-foot-high ceiling, are they in melee range of a creature on the ground?

Can a cyclic Amine form an Amide?

Stark VS Thanos

How can I close a gap between my fence and my neighbor's that's on his side of the property line?

Is lying to get "gardening leave" fraud?

Was the ancestor of SCSI, the SASI protocol, nothing more than a draft?

Unexpected email from Yorkshire Bank

Copy line and insert it in a new position with sed or awk

Field Length Validation for Desktop Application which has maximum 1000 characters

If Earth is tilted, why is Polaris always above the same spot?

Why is Arya visibly scared in the library in S8E3?

Is balancing necessary on a full-wheel change?

Unidentified items in bicycle tube repair kit

A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours

How to efficiently calculate prefix sum of frequencies of characters in a string?

Feels like I am getting dragged into office politics

How to assert on pagereference where the endpoint of pagereference is predefined

Is it always OK to ask for a copy of the lecturer's slides?

Save terminal output to a txt file

Was Hulk present at this event?

CRT Oscilloscope - part of the plot is missing

Pigeonhole Principle Problem

What was the state of the German rail system in 1944?



Capture git output into variable


Interpret backspaces in fileHow bash treats “> >()”Pipe ssh's output (stderr and stdout) to different commandsPipe filelist into 'git add'bash: tee eats newlines after execColour-coordinate symlinks/softlinks based on where they refer toSave into file git fetch terminal outputGet PID and return code from 1 line bash callRedirection and piping for greppingLog redirection happens to rotated log instead of new log getting created






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







0















If I run a command in a subshell, I can collect the stdout into a variable, such as:



var=$(echo 'hello world')
echo $var


Will print 'hello world' as expected.



If I add colour and a new line, this too is ok:



var=$(echo "Text in ne[34mBlue")
echo -e $var


Prints "Text in Blue" with the word 'Blue' coloured and on the next line as expected.



However if I try this with git output, such as



var=$(git status)
echo $var


It loses all the newlines and colouring.



How can I capture the output of a git command and print it later on, while preserving formatting and colouring in bash?










share|improve this question





























    0















    If I run a command in a subshell, I can collect the stdout into a variable, such as:



    var=$(echo 'hello world')
    echo $var


    Will print 'hello world' as expected.



    If I add colour and a new line, this too is ok:



    var=$(echo "Text in ne[34mBlue")
    echo -e $var


    Prints "Text in Blue" with the word 'Blue' coloured and on the next line as expected.



    However if I try this with git output, such as



    var=$(git status)
    echo $var


    It loses all the newlines and colouring.



    How can I capture the output of a git command and print it later on, while preserving formatting and colouring in bash?










    share|improve this question

























      0












      0








      0








      If I run a command in a subshell, I can collect the stdout into a variable, such as:



      var=$(echo 'hello world')
      echo $var


      Will print 'hello world' as expected.



      If I add colour and a new line, this too is ok:



      var=$(echo "Text in ne[34mBlue")
      echo -e $var


      Prints "Text in Blue" with the word 'Blue' coloured and on the next line as expected.



      However if I try this with git output, such as



      var=$(git status)
      echo $var


      It loses all the newlines and colouring.



      How can I capture the output of a git command and print it later on, while preserving formatting and colouring in bash?










      share|improve this question














      If I run a command in a subshell, I can collect the stdout into a variable, such as:



      var=$(echo 'hello world')
      echo $var


      Will print 'hello world' as expected.



      If I add colour and a new line, this too is ok:



      var=$(echo "Text in ne[34mBlue")
      echo -e $var


      Prints "Text in Blue" with the word 'Blue' coloured and on the next line as expected.



      However if I try this with git output, such as



      var=$(git status)
      echo $var


      It loses all the newlines and colouring.



      How can I capture the output of a git command and print it later on, while preserving formatting and colouring in bash?







      bash io-redirection git






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 22 mins ago









      AlexAlex

      1901311




      1901311






















          0






          active

          oldest

          votes












          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%2f516282%2fcapture-git-output-into-variable%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f516282%2fcapture-git-output-into-variable%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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...