4

I'm trying to save the output of a git command to an environment variable in a GitHub Actions step and it's grabbing the first line of the output and leaving off the rest. The container this is running on is ubuntu-latest.

Here's how I'm trying to capture it:

TMP_CHANGES=`git log origin/master..`

What I expect from echo $TMP_CHANGES:

commit f179fb811618cc5a2f07637a2ecb394a43ebee21
Author: DannyHinshaw <[email protected]>
Date:   Tue Jan 14 07:38:29 2020 -0500
    Testing commits diff
commit ed596d2ff2e5bd9801eae6ece7abf627db89f82b
Author: DannyHinshaw <[email protected]>
Date:   Tue Jan 14 07:38:28 2020 -0500
    Bump version -> v1.2.1-101
commit 40f88031293aba0221b65ed1d2a8295b651ef91b
Author: DannyHinshaw <[email protected]>
Date:   Tue Jan 14 07:35:04 2020 -0500
    Testing commits diff

What I get:

commit f179fb811618cc5a2f07637a2ecb394a43ebee21

What am I missing? How can I capture and save the full multiline output to the variable while preserving multiline formatting?

11
  • It is possible a part of the output you see on your terminal comes from the standard output, commit f179fb811618cc5a2f07637a2ecb394a43ebee21 and another part from the error output. Commented Jan 14, 2020 at 13:02
  • Does this answer your question? Capturing multiple line output into a Bash variable Commented Jan 14, 2020 at 13:41
  • @LéaGris no, I've seen that and tried it as well. Commented Jan 14, 2020 at 13:52
  • @DjH : What does wc <<<$TMP_CHANGES say? Commented Jan 14, 2020 at 14:10
  • 1
    @user1934428 The fact that an error is not relevant to the question does not mean it should go unmentioned. There is a great deal of confusion regarding many topics that is often revealed through comments unrelated to a particular question which IMO should be cleared up rather than ignored. Commented Jan 14, 2020 at 14:47

1 Answer 1

3

Testing on Ubuntu 18.04.3 LTS

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:    18.04
Codename:   bionic

$ git --version
git version 2.17.1

Get log

GT=$(git log -n3 origin/master..)

Echo without ""

$ echo $GT
commit c7c1d60c01b23ba225d79d350d74d0f8990ea8df Author: Ivan <[email protected]> Date: Tue Jan 14 16:05:16 2020 +0300 ref test2 commit 7a52ab307dd6eb2c88cdee83d40dbf2f2ed8c218 Author: Ivan <[email protected]> Date: Tue Jan 14 15:47:16 2020 +0300 ref test2 commit 8f0a2c081a4e731b676c95991d9b182fadd71a95 Author: Ivan <[email protected]> Date: Tue Jan 14 12:45:13 2020 +0300 add more test files

Echo with ""

$ echo "$GT"
commit c7c1d60c01b23ba225d79d350d74d0f8990ea8df
Author: Ivan <[email protected]>
Date:   Tue Jan 14 16:05:16 2020 +0300

    ref test2

commit 7a52ab307dd6eb2c88cdee83d40dbf2f2ed8c218
Author: Ivan <[email protected]>
Date:   Tue Jan 14 15:47:16 2020 +0300

    ref test2

commit 8f0a2c081a4e731b676c95991d9b182fadd71a95
Author: Ivan <[email protected]>
Date:   Tue Jan 14 12:45:13 2020 +0300

    add more test files
Sign up to request clarification or add additional context in comments.

1 Comment

I've tried just about every variaton of this that I could think of and it's the same. Do you think maybe it's the way GH Actions are calling the commands? I just found out that looks like this bin/bash -e {0}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.