I use xclip to get my current path in my clipboard this way :
pwd | xclip -selection c
it almost works : if you paste (ctrl v) in an empty file, you will see that there is a trailing carriage return. It's very annoying since if you past in a term, then it immediately executes your expression, even if you did not finished to type.
The problem is the same with :
echo "titi" | xclip -selection c
- is it due to xclip ?
- Why xclip would add a trailing carriage return ?
- Is there a carriage return at the end of every string in bash ?
The problem comes from the commands that add a new line character (
\n
) at the end of their output,pwd
is one of these, as isecho
(without-n
).One solution is to strip the new line out of the text before sending it to
xclip
, for instance :pwd | tr -d "\n" | xclip -selection c
Here we use the
tr
tool to remove the new line.