8

I have seen this post: how-can-i-copy-the-output-of-a-command-directly-into-my-clipboard

I have got this alias

# Redoes the last command and copies the output to clipboard

  alias cl="fc -e -|pbcopy"

However I would like an alias or a function that doesn't redo the last command, but does copy the output of the last command.

Community
  • 1
  • 1
dimitrieh
  • 401
  • 3
  • 17
  • 1
    Another relevant question: http://stackoverflow.com/questions/5955577/bash-automatically-capture-output-of-last-executed-command-into-a-variable – Adi Levin Jan 22 '16 at 11:12
  • 1
    Can we convert the solution to that question into a solution for this one? – dimitrieh Jan 22 '16 at 11:20

2 Answers2

1

Shells in common use on Linux (such as bash) do not preserve the output from the previous command, so re-execution is the only solution unless you add code to do the preservation yourself. Pbcopy isn't always installed, xclip seems more commonly installed:

    ls -l
    !! | xclip
-1

try this,

!-1 | pbcopy

or so if you want alias

alias cl="!-1 | pbcopy"
  • 2
    this is an inferior version of ```fc -e -|pbcopy``` it wants to redo the last command with the pbcopy behind it and doesn't do so automatically. It needs to only copy the output of the previous command **without redoing the last command** – dimitrieh Jan 22 '16 at 12:21
  • ```!!``` is the short version of ```!-1``` btw ;) so who does have the solution? – dimitrieh Jan 22 '16 at 12:24