7

I know this command will paste the clipboard contents into a file:

xclip -out -selection clipboard >> file.txt

If I want to paste clipboard content into a variable like a string what do I do?

4 Answers 4

6

To assign the output of a command to a variable, you can use command substitution:

myvar=$( command )
echo "$myvar"
0
4

You can output by echo your clipboard contents using xclip:

clipboard_content=`xclip -o -selection clipboard`
echo "$clipboard_content"
0

You can output echo your clipboard by xsel also:

myvar=$( xsel -ob )
echo "$myvar"
0

I am currently using

#!/bin/bash
# collect contents of clipboard
ln=$(xsel -ob)
#
# manipulate contents of the variable ln
#
# "post result back to clipboard, -n without newline at end
echo -n $ln | xclip -sel c

xsel and xclip were installed using Synaptic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.