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?

msw
  • 42,753
  • 9
  • 87
  • 112
Do Thanh Tung
  • 1,223
  • 2
  • 19
  • 30

4 Answers4

6

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

myvar=$( command )
echo "$myvar"
user000001
  • 32,226
  • 12
  • 81
  • 108
4

You can output by echo your clipboard contents using xclip:

clipboard_content=`xclip -o -selection clipboard`
echo "$clipboard_content"
WinEunuuchs2Unix
  • 1,801
  • 1
  • 17
  • 34
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