Take the 2-minute tour ×

I am often having to copy and paste text from the terminal. Is there a way to redirect the output of a command into a shell variable or another command that would place the output in the clipboard?

share|improve this question
add comment

2 Answers

up vote 13 down vote accepted

Use pbcopy and pbpaste. Anything sent to pbcopy goes into the clipboard. Running pbpaste sends the contents of the clipboard to standard output and you can chain them just like all other commands.

You can find some example uses here: http://osxdaily.com/2007/03/05/manipulating-the-clipboard-from-the-command-line/

share|improve this answer
awesome! Thank you! –  kakyo Nov 1 '13 at 18:43
add comment

pbcopy and pbpaste replace non-ASCII characters with question marks in some environments. It can be avoided by setting LC_CTYPE to UTF-8.

LC_CTYPE=UTF-8 pbpaste

You could also use osascript:

osascript -e 'on run {input}
set the clipboard to input
end' "ä"

osascript -e 'the clipboard as text'
share|improve this answer
add comment

Your Answer


