How to prepend lines to git command output

user393961

This is part of a larger script but I distilled the problem down to this:

cm_safe(){
   git push | while read line; do
    echo "cm safe push: $line"
   done;
}

I want to prepend git output, so it would look like:

cm safe push: Everything up-to-date

but instead I just get:

Everything up-to-date

Is git writing to the tty or something directly? I dunno what's going on.

jesse_b

git push writes to stderr so you would have to redirect that to stdout in order for it to be sent over the pipeline:

cm_safe(){
   git push 2>&1 | while IFS= read -r line; do
     echo "cm safe push: $line"
   done
}

Alternatively you could do:

git push |& while IFS= read -r line; do

I recommend reading What are the shell's control and redirection operators? for more information.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to prepend value to the cat command output without modifying a file?

From Dev

How to prepend multiple lines to a file

From Dev

How to separate command output to individual lines

From Dev

How to prepend filename to last lines of files found through find command in Unix

From Dev

How to make git output usage for any command?

From Dev

how to read git show command output

From Dev

How to make git output usage for any command?

From Dev

how to read git show command output

From Dev

How to create an array from the lines of a command's output

From Dev

How to limit the number of lines a command's output has available in bash?

From Dev

How to create an array from the lines of a command's output

From Dev

How to filter out lines of a command output that occur in a text file?

From Dev

How to insert tabs before output lines from a executed command

From Dev

How to store multiple lines of command output to a variable using JSch

From Dev

how to read certain lines of a file that is the output of fc command with a batch script

From Dev

how to get only the deleted lines by git diff command?

From Dev

Output of git pull command

From Dev

Run command output lines as another command in linux

From Dev

How to prepend only those lines with tabs/spaces in a file, with esc character?

From Dev

How to prepend a string to only the lines of text which are numbers

From Dev

Prepend lines to HTML file

From Dev

How do I store output of a git command in a Perl array or scalar?

From Dev

How to run command on git log output per commit using bash

From Dev

How do I append/prepend a timestamp to grep output?

From Dev

How to redirect output to a log file from cron and prepend timestamp?

From Dev

Prepend to filename with find command

From Dev

redirecting git command output to another

From Dev

Color output of specific git command

From Dev

how is this done using AWK / SED : Insert lines regularly and then prepend the rest of the lines for every Nth Line

Related Related

  1. 1

    How to prepend value to the cat command output without modifying a file?

  2. 2

    How to prepend multiple lines to a file

  3. 3

    How to separate command output to individual lines

  4. 4

    How to prepend filename to last lines of files found through find command in Unix

  5. 5

    How to make git output usage for any command?

  6. 6

    how to read git show command output

  7. 7

    How to make git output usage for any command?

  8. 8

    how to read git show command output

  9. 9

    How to create an array from the lines of a command's output

  10. 10

    How to limit the number of lines a command's output has available in bash?

  11. 11

    How to create an array from the lines of a command's output

  12. 12

    How to filter out lines of a command output that occur in a text file?

  13. 13

    How to insert tabs before output lines from a executed command

  14. 14

    How to store multiple lines of command output to a variable using JSch

  15. 15

    how to read certain lines of a file that is the output of fc command with a batch script

  16. 16

    how to get only the deleted lines by git diff command?

  17. 17

    Output of git pull command

  18. 18

    Run command output lines as another command in linux

  19. 19

    How to prepend only those lines with tabs/spaces in a file, with esc character?

  20. 20

    How to prepend a string to only the lines of text which are numbers

  21. 21

    Prepend lines to HTML file

  22. 22

    How do I store output of a git command in a Perl array or scalar?

  23. 23

    How to run command on git log output per commit using bash

  24. 24

    How do I append/prepend a timestamp to grep output?

  25. 25

    How to redirect output to a log file from cron and prepend timestamp?

  26. 26

    Prepend to filename with find command

  27. 27

    redirecting git command output to another

  28. 28

    Color output of specific git command

  29. 29

    how is this done using AWK / SED : Insert lines regularly and then prepend the rest of the lines for every Nth Line

HotTag

Archive