1

I have read many threads on this topic, but none of the solutions have worked for me.

I am trying to do the following:

RELEASE_COMMAND_OUTPUT=$(exec ~/temp/execs/github-release release --user patick --repo $REPO_NAME --tag $RELEASE_VERSION --name $RELEASE_VERSION --description "$DESC")

but the output of ./github-release is not stored in the RELEASE_COMMAND_OUTPUT variable.

I'm aware of the concept of command substitution, but none of the solutions I've tried have worked. What am I doing wrong?

4
  • 2
    Why the exec? Is the output of github-release written to standard output? What is the expected output (I'm not familiar with the github-release command and I can't find a manual for it)?
    – Kusalananda
    Jun 15, 2017 at 17:43
  • 1
    If the output you are seeking to store is being written to standard error rather than standard output, add 2>&1 to the end of your subshell and it too will be captured into the variable.
    – DopeGhoti
    Jun 15, 2017 at 17:45
  • Is "--user patick" a typo in the question or a typo in the command? Could it be that you just get an error message in the latter case? What happens if you run the command (cut and paste please - do not retype) by itself, not in a command substitution? And as @DopeGothi indicates, if you redirect stdout, do you get anything? What value does RELEASE_COMMAND_OUTPUT get?
    – NickD
    Jun 15, 2017 at 17:47
  • @DopeGhoti that works! I'm pulling the executable from another source, and I hadn't considered that it may be output to stderr rather than stdout. Jun 15, 2017 at 17:49

1 Answer 1

1

As explained in your question's comments, the variable RELEASE_COMMAND_OUTPUT will only get the STDOUT(standard output) of your command but not the STDERR (standard error), as it seems to be your case.

When in doubt about the output of your command you can use process substitution to mark the STDERR in red as in the following example:

command 2> >(while read line; do echo -e "\e[01;31m$line\e[0m" >&2; done)

Which is redirecting (the 2> part) the STDERR of the command as input to the while block which will print it in red in the terminal.

You can also do the opposite, marking the STDOUT as red with:

command | grep .

Because grep act only in STDOUT

NOTE: in some systems you may need to enable the color in grep using the flag --color=auto. On Macos and Linux usually it's enable by default.

4
  • The grep trick only works if your grep is configured to color matching lines, of course. It frequently is on Linux, but the idea will make no sense at all on platforms where it isn't.
    – tripleee
    Jun 16, 2017 at 3:50
  • Yes, macos enable colors by default. Anyway I added a note about the possibility of not enabled colors on some systems. Thank you! Jun 16, 2017 at 4:16
  • The option might not even be available on some non-GNU platfoms but at least it's understandable now. I don't see why MacOS specifically is relevant here, though I suppose it completes the picture somewhat.
    – tripleee
    Jun 16, 2017 at 5:18
  • Macos is cited just as a flavor of Unix ;-) Jun 16, 2017 at 5:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .