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?
Use "pbcopy" to copy content of file to your clipboard. the command will copy all content from "file. txt" directly on your clipboard.
Similarly, you can use Ctrl+shift+C to copy text from the terminal and then use it to paste in a text editor or web browser using the regular Ctrl+V shortcut. Basically, when you are interacting with the Linux terminal, you use the Ctrl+Shift+C/V for copy-pasting.
In Terminal, select something and then within the same Terminal window do one of the following: click and drag the selection (a bit; the mouse pointer will change), and release to paste (hit Esc while dragging to cancel) or: paste using Shift-Command-V.
Anytime you use the common shortcuts Command/⌘+X (cut) or Command/⌘+ C (copy), your Mac handily stores what you copy onto the Clipboard. This saved content is later made available when you use Command/⌘+V (paste) shortcut.
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/
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With