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?
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?
To assign the output of a command to a variable, you can use command substitution:
myvar=$( command )
echo "$myvar"
You can output by echo
your clipboard contents using xclip
:
clipboard_content=`xclip -o -selection clipboard`
echo "$clipboard_content"
You can output echo your clipboard by xsel also:
myvar=$( xsel -ob )
echo "$myvar"
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
© 2022 - 2024 — McMap. All rights reserved.