I run the command pbpaste in Terminal (bash) to get the result of my clipboard, but unlike other commands which leave the cursor at a new line below the previous stdout, pbpaste leaves it to the right of it, as in the example, showing the command sandwiched between two echo hellos:

hostname:~ jesse$ echo hello
hostname:~ jesse$ pbpaste
https://itunes.apple.com/us/app/noizio/id928871589?mt=12hostname:~ jesse$ echo hello
hostname:~ jesse$ 

Why is it like this? It seems very odd and makes it difficult to read.

  • What exactly did you copy?
    – mmmmmm
    Apr 8, 2016 at 10:16
  • @Mark The characters in the string on line 4 of my code before "hostname"
    – jsejcksn
    Apr 8, 2016 at 10:18

2 Answers 2


pbpaste pastes exactly what you copy.

In your case you have copied the line not including the CR/LF at the end. To get the return you need to copy from the start of the line to the beginning of the next line

From @patrix comment

Most commands do end with a CR/LF. e.g. echo "Hello" will put out a newline, however for echo this can be changed echo -n "Hello".

If you want you can add a newline after a pbpaste by using echo "$(pbpaste)" instead.

  • So what you're also saying is that almost all other commands with output include a terminating newline?
    – jsejcksn
    Apr 8, 2016 at 10:34
  • @JesseJackson Not directly. pbpaste outputs whatever is in the clipboard, which usually doesn't contain a newline. echo some text adds a newline by default, but that's something that you can prevent from happening with echo -n some text. If you want to ensure a newline after pbpaste, use echo $(pbpaste) instead.
    – nohillside
    Apr 8, 2016 at 11:33
  • @patrix Which other commands don't include a newline by default? I've never seen this behavior in bash before using the pbpaste command.
    – jsejcksn
    Apr 8, 2016 at 12:34
  • @JesseJackson not many but pbpaste is copying that it gets which is need for uses where it is substituted in the middle of a command. As I noted cut and paste usually for me cuts the newline as I copy to the beginning of the line. Also see questions on python without readline
    – mmmmmm
    Apr 8, 2016 at 12:36
  • @JesseJackson The difference is between commands intended to output some text in Terminal (like echo, ls etc.) and commands intended to return text/data from somewhere. The former add a newline automatically, the later just return (print) whatever they got (which in case of the clipboard may or may be without a newline).
    – nohillside
    Apr 8, 2016 at 12:51

This doesn't directly answer your question about pbpaste specifically, but I'm a user of zsh (with oh-my-zsh) and it handles the scenario you describe with the outcome you want for any terminal output.

➜  ~ echo -n hello
➜  ~
➜  ~
➜  ~ /bin/bash
bash-3.2$ echo -n hello

I realize it's bringing out the bazooka to kill a mosquito, but it solves your real problem where lack of a new line on what you pasted isn't handled gracefully.

  • Nice info, even if it is not relevant.
    – jsejcksn
    Apr 8, 2016 at 12:31

You must log in to answer this question.

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