2

Often I'd like the command I just typed to put into the clipboard, and I'd like to do it from the command line.

I came up with:

alias cl="fc -ln -1 | sed 's/^\s*//' | xsel -b"

To alias cl to that pipeline which seems to achieve the desired effect, but it seems complicated and has a trailing newline that I don't want. Any obvious and simpler way which doesn't have a trailing newline?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
BeeOnRope
  • 538
  • 3
  • 13

2 Answers2

0

You can use tr -d "\n" to get rid of the new line character.

finswimmer
  • 876
  • 5
  • 8
0

alias cl="fc -ln -1 | sed 's/^\s*//' | tr -d '\n' | xsel -b"

  • [Brevity is acceptable, but fuller explanations are better](https://unix.stackexchange.com/help/how-to-answer). – Kusalananda May 01 '22 at 22:02
  • This is basically a (fleshed out) copy of the other answer.   You have not added enough information or insight to qualify as a separate answer.   If and when you do build on somebody else’s answer, you should give credit to the original answer, both by linking to it and by citing the author’s name. – G-Man Says 'Reinstate Monica' May 02 '22 at 00:04