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 <danny@nulleffort.com>
Date:   Tue Jan 14 07:38:29 2020 -0500
    Testing commits diff
commit ed596d2ff2e5bd9801eae6ece7abf627db89f82b
Author: DannyHinshaw <danny@nulleffort.com>
Date:   Tue Jan 14 07:38:28 2020 -0500
    Bump version -> v1.2.1-101
commit 40f88031293aba0221b65ed1d2a8295b651ef91b
Author: DannyHinshaw <danny@nulleffort.com>
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?

DjH
  • 1,448
  • 2
  • 22
  • 41
  • 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. – Pierre François Jan 14 '20 at 13:02
  • Does this answer your question? [Capturing multiple line output into a Bash variable](https://stackoverflow.com/questions/613572/capturing-multiple-line-output-into-a-bash-variable) – Léa Gris Jan 14 '20 at 13:41
  • @LéaGris no, I've seen that and tried it as well. – DjH Jan 14 '20 at 13:52
  • @DjH : What does `wc <<<$TMP_CHANGES` say? – user1934428 Jan 14 '20 at 14:10
  • @user1934428 `1 0 1` is the ouptut – DjH Jan 14 '20 at 14:18
  • This can't be. It would mean that TMP_CHANGES would hold only one single character. Please compy and paste the commands `TMP_CHANGES=$(git log origin/master..); wc <<<$TMP_CHANGES; echo "TMP_CHANGES=$TMP_CHANGES"` and copy and paste back the output. – user1934428 Jan 14 '20 at 14:24
  • @user1934428 no difference – DjH Jan 14 '20 at 14:28
  • The title says "environment variable", but there are no environment variables here. You have a variable named `TMP_CHANGES`. Merely naming it in ALL CAPS does not make it an environment variable. – William Pursell Jan 14 '20 at 14:29
  • @WilliamPursell : You are right, but it does not matter whether the variable is exported or not. – user1934428 Jan 14 '20 at 14:34
  • 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. – William Pursell Jan 14 '20 at 14:47
  • @WilliamPursell : Agreed - in particular with a question as confusing as this one.... – user1934428 Jan 14 '20 at 14:57

1 Answers1

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 <user@pisem.net> Date: Tue Jan 14 16:05:16 2020 +0300 ref test2 commit 7a52ab307dd6eb2c88cdee83d40dbf2f2ed8c218 Author: Ivan <user@pisem.net> Date: Tue Jan 14 15:47:16 2020 +0300 ref test2 commit 8f0a2c081a4e731b676c95991d9b182fadd71a95 Author: Ivan <user@pisem.net> Date: Tue Jan 14 12:45:13 2020 +0300 add more test files

Echo with ""

$ echo "$GT"
commit c7c1d60c01b23ba225d79d350d74d0f8990ea8df
Author: Ivan <user@pisem.net>
Date:   Tue Jan 14 16:05:16 2020 +0300

    ref test2

commit 7a52ab307dd6eb2c88cdee83d40dbf2f2ed8c218
Author: Ivan <user@pisem.net>
Date:   Tue Jan 14 15:47:16 2020 +0300

    ref test2

commit 8f0a2c081a4e731b676c95991d9b182fadd71a95
Author: Ivan <user@pisem.net>
Date:   Tue Jan 14 12:45:13 2020 +0300

    add more test files
Ivan
  • 6,188
  • 1
  • 16
  • 23
  • 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}` – DjH Jan 14 '20 at 13:52