
The problem with xclip seems to be that, when launched from a non-interactive shell, it doesn't become fully independent of the controlling terminal and dies when the terminal process exits. + xterm -e bash -c 'echo abc|xsel -input -clipboard sleep 3'īoth xclip and xsel work by detaching from the terminal and spawning a child process that is responsible for supplying the selection(s) on demand (until a new selection is made): $ ps -H

xterm -e bash -c "echo abc|xsel -input -clipboard sleep 3"& Xterm -e bash -c "echo abc|xsel -input -clipboard sleep 3"& Xterm -e bash -c "echo abc|xclip -selection clipboard sleep 3"& Using xsel instead of xclip for manipulating the X clipboard eliminates the issue (note that xclip was replaced with xsel only when placing data into the clipboard, and not when reading from the clipboard): $ cat xclip_test The author of the original question on Stackoverflow has identified this to be a problem in xclip. The problem persists when replacing gnome-terminal with xterm:Īlso it is not unique to bash - it is reproduced with dash, too. Is this something having a sensible explanation? However clear_console doesn't seem to deal with the clipboard besides, the example doesn't run bash as a login shell.

bash_logout just in case and found a call to clear_console utility. I am on Ubuntu 16.04, using default GNU bash ( version 4.3.46(1)-release (x86_64-pc-linux-gnu)) with no customizations to bash rc files. + gnome-terminal -x bash -c 'echo 123|xclip -selection clipboard sleep 3'Įrror: target STRING not available #!!!!!!!!!!!!! + gnome-terminal -x bash -i -c 'echo abc|xclip -selection clipboard sleep 3' VimTip771 and VimTip964 refer to an extra utility named xclip which is only for. Gnome-terminal -x bash -c "echo 123|xclip -selection clipboard sleep 3" In general using + and is much more reliable than using CTRL-SHIFT-V. Gnome-terminal -x bash -i -c "echo abc|xclip -selection clipboard sleep 3" However, after the terminal is closed, the clipboard contents survives if bash was run in interactive mode, but is lost if bash was run in non-interactive mode. While the terminal is open, querying the clipboard returns the text that was placed in it regardless of whether bash is run in interactive or non-interactive mode. The test opens a gnome terminal and runs a bash script in it that places (via xclip) some text in the X system clipboard. xml:id=”_copy_stdout_to_the_clipboard”>Ĭopy stdout of a command/program to the clipboard.While investigating a problem described in a question at stackoverflow I simplified it down to a test case demonstrating that in non-interactive mode bash seems to clear the X system clipboard before exiting. You might also like to read link:/shell/reading-and-understanding-command-line-documentation.html. Again, check the man pages for syntax details. Xsel has -p as the short version for -primary and -b for -clipboard. For instance, if you copy from the command line to the primary selection, make sure you attempt a paste by clicking the mouse wheel, otherwise you may mistakenly think the commands are not working.Īlthough xclip sounds like “X clipboard” and xsel sounds like “X selection”, both programs can handle both the clipboard and the primary selection. Just make sure to copy and paste either using the clipboard or the primary selection accordingly. For that you can use an external tool, like a text editor to copy/paste and see if your commands for copying and pasting from the command line are working as expected.

You’ll likely want to try these commands out instead of just reading about them. Long names use - like in -output and a single - for the short version, like in -o. Note that xclip parameters always start with a single -, like in -version. Intel Dual-Core CPU E5400 (soc 775) 2.70GHz, onboard Intel G33, Asus MB P5KPL-AM IN (Intel G31), D-Link 2750u modem+router, 64-bit Debian Testing, Mate 1. clipboard could be abbreviated to clip or even c. Even if xclip can do that with a single command, wipe clipboard clean, that would be good for me. For example, -v cannot be an abbreviation because it could mean -verbose or -version. Xclip has options like -selection, and they can be abbreviated to shorter names (like -sel or even -s) as long as they do not conflict to other options. # Probably something like this on deb and rpm based distros:
