I have the following in a shell script

fulloutput="<pre>$(df -h /;sudo shutdown -r +1 )</pre>"

Later in the script I echo this variable (it's piped to sendmail but that's irrelevant here) but I only get the output from the df command, not the shutdown.

I have tried without sudo and I have tried separating the commands like follows...

fulloutput="<pre>$(df -h /) $(sudo shutdown -r +1 )</pre>"

But still only get the output from the df command.

It's not a big issue, but it would be nice to get the output from shutdown as an indicator that that part of my script has executed succesfully.

  • @steeldriver Is it possible to redirect it to stdout? I tried ">&1" after the shutdown command but that didn't work.
    – MrVimes
    Jul 31, 2019 at 13:47
  • That worked. If you would like to post that as an answer I will accept it.
    – MrVimes
    Jul 31, 2019 at 13:49

1 Answer 1


Your command substitution captures stdout; the shutdown message is likely written to stderr.

To redirect stderr to stdout so that it is captured as well, add 2>&1 i.e.

$(df -h /; sudo shutdown -r +1 2>&1)

You must log in to answer this question.

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