0

This question already has an answer here:

Here is my bash script

while ./clipnotify;
do
  SelectedText="$(xsel)"
  CopiedText="$(xsel -b)"
  Check="$(xclip -selection clip -t TARGETS -o)"
  if ["$Check" != *"image"*]; then
    if [[ $SelectedText != *"file:///"* ]]; then
      ModifiedTextPrimary="$(echo "$SelectedText" | tr -s '\n' ' ')"
      echo -n "$ModifiedTextPrimary" | xsel -i
    fi
    if [[ $CopiedText != *"file:///"* ]]; then
      ModifiedTextClipboard="$(echo "$CopiedText" | tr -s '\n' ' '  )"
      echo -n "$ModifiedTextClipboard" | xsel -bi
    fi
  fi
done

Output of xclip -selection clip -t TARGETS -o when text copied to clipboard :

TIMESTAMP
TARGETS
MULTIPLE
SAVE_TARGETS
UTF8_STRING
COMPOUND_TEXT
TEXT
STRING
text/plain;charset=utf-8
text/plain;charset=ANSI_X3.4-1968
text/plain

Output of xclip -selection clip -t TARGETS -o when image copied to clipboard :

application/x-qt-image
image/png
image/bmp
image/bw
image/cur
image/eps
image/epsf
image/epsi
image/icns
image/ico
image/jp2
image/jpeg
image/jpg
image/pbm
BITMAP
image/pcx
image/pgm
image/pic
image/ppm
PIXMAP
image/rgb
image/rgba
image/sgi
image/tga
image/tif
image/tiff
image/wbmp
image/webp
image/xbm
image/xpm
TARGETS
MULTIPLE
TIMESTAMP
SAVE_TARGETS

What I am trying to do is save output of xclip -selection clip -t TARGETS -o to variable Check and use if statment to check if the variable contains the word "image" so I can detect that clipboard contains an image and disable further execution.

When running the script I get error

/home/user/Applications/Scripts/CopyWithoutLinebreaks/debug.sh: line 16: [application/x-qt-image
image/png
image/bmp
image/bw
image/cur
image/eps
image/epsf
image/epsi
image/icns
image/ico
image/jp2
image/jpeg
image/jpg
image/pbm
BITMAP
image/pcx
image/pgm
image/pic
image/ppm
PIXMAP
image/rgb
image/rgba
image/sgi
image/tga
image/tif
image/tiff
image/wbmp
image/webp
image/xbm
image/xpm
TARGETS
MULTIPLE
TIMESTAMP
SAVE_TARGETS: No such file or directory

The script works when the check for image condition is removed.

Any way resolve the error ?

marked as duplicate by Inian, muru, Fabby, Toby Speight, Anthony Geoghegan Sep 4 at 10:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Shell scripts are extremely sensitive to lack of white-spaces when using the built-ins for comparison operations

if ["$Check" != *"image"*]; then
#  ^^                    ^^       lack of spaces

if [ "$Check" != *"image"* ]; then
#                                 right syntax

There should have been a space after the [ and the start of the next character and similarly before ] without which the syntax evaluation for the [..] fails, producing the error message.

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