Commands
We can also copy and paste using only the command line. xclip
interacts with the same primary and clipboard selections mentioned above, reading from standard input and printing selection contents to standard output. This can be useful in many situations. For one thing, it guarantees that what you are copying is exact – it will include any non–printable characters as they are:
$ printf 'a\tb\0c' | xclip
$ xclip -out | od --address-radix=n --format=c --width=1
a
\t
b
\0
c
In the first command, printf
outputs the characters a
, Tab (\t
), b
, NUL (\0
) and c
to standard output. xclip
reads that from standard input and saves it to the default (primary) selection of the X Window System clipboard. In the second command we print the contents of the primary selection to standard output and format it using od
into their individual characters.
The
od
options in detail:--address-radix=n
disables printing the offset of each line,--format=c
formats printable characters as themselves and non–printable characters as theirprintf
-style backslash escapes, and--width=1
outputs one byte per line.
This page is a preview of The newline Guide to Bash Scripting