1

When I try to pastebin 2 command like this:

echo Merry && echo Christmas | pastebinit

It only pastebins the second command, and gives the first as output:

Merry
http://paste.ubuntu.com/9605648/

Now I could just do:

echo Merry Christmas | pastebinit

And that would work, but I want to run 2 separate commands, and pipe the output to pastebinit, I can't:

sudo apt-get install christmas && sudo apt-get update | pastebinit

does not seem to work.

Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
Tim
  • 32,274
  • 27
  • 118
  • 177

3 Answers3

4

Wrap it to make a compound command:

{ echo Merry && echo Christmas;} | pastebinit

In general, to pipe the output of multiple commands in sequence to another command, do:

{ cmd1; cmd2; ...;} | cmd

or

(cmd1; ... ) | cmd
Tim
  • 32,274
  • 27
  • 118
  • 177
muru
  • 193,181
  • 53
  • 473
  • 722
  • @Tim As I understand it, for the case of pipes, no. Braces are usually used to run commands in the current shell and parentheses for running in a subshell, but pipes force the usage of a subshell anyway. But I could be wrong. It looks like a good question for [unix.se]. – muru Dec 23 '14 at 20:22
  • 1
    Okay - I believe that edit is needed btw. – Tim Dec 23 '14 at 20:23
0

Is there a reason you couldn't first redirect the output of the two commands into a file (using append for the output of the second command), and then pipe that to pastebinit?

echo Merry > out.txt && echo Christmas >> out.txt && cat out.txt | pastebinit

Maybe redirect stderr to the out file also.

muru
  • 193,181
  • 53
  • 473
  • 722
Stephen Davison
  • 101
  • 1
  • 4
  • If you're going to `cat` anyway, avoid manually creating a file: `cat <(echo Merry) <(echo Christmas) | pastebinit` – muru Dec 24 '14 at 06:09
  • OP doesn't want the second command executed if the first one returns an error condition. Unfortunately, your edit omits that requirement. Perhaps this: cat <(echo Merry && echo Christmas) | pastebinit – Stephen Davison Dec 24 '14 at 21:30
0

Here follows a work-around to answer the question of "how do I grab complex output on the CLI?"

Should be useful:

thufir@dur:~$ 
thufir@dur:~$ script xmas
Script started, file is xmas
thufir@dur:~$ 
thufir@dur:~$ echo Merry && echo Christmas
Merry
Christmas
thufir@dur:~$ 
thufir@dur:~$ exit
exit
Script done, file is xmas
thufir@dur:~$ 
thufir@dur:~$ cat xmas 
Script started on 2017-10-27 06:37:59-0700
thufir@dur:~$ 
thufir@dur:~$ echo Merry && echo Christmas
Merry
Christmas
thufir@dur:~$ 
thufir@dur:~$ exit
exit

Script done on 2017-10-27 06:38:23-0700
thufir@dur:~$ 
thufir@dur:~$ pastebinit xmas
http://paste.ubuntu.com/25830406/
thufir@dur:~$ 

Here's the pastebin file on ubuntu, as above. Reference man script for how to use typescript.

Note that you can execute scripts, interact, etc. The script command just logs everything into a file. Not quite sure how to make it more readable without futzing with the console/shell configuration...

Basically, if you turn off all colors, etc, it looks better.

Thufir
  • 4,441
  • 17
  • 80
  • 146