1

As an FYI this is on Linux.

I want to have one of the options in a script to be to pull the selected text. So I start my script

#!/bin/bash

xclip -o > ~/bin/temp.txt

However, if I don't have anything selected this throws the error

./test
Error: target STRING not available

Can I check whether something is selected and skip this command if there isn't?

user1543042
  • 3,422
  • 1
  • 17
  • 31

1 Answers1

1

I don't know anything about xclip, but how about something like:

myclip=$(xclip -o) if [ -n "$myclip" ]; then echo $myclip > ~/bin/temp.txt fi

If $myclip is unset or has zero length (=""), nothing will be written to temp.txt.

meatspace
  • 859
  • 16
  • 25