I'm having trouble with GhostScript accepting shell script variables for filenames, if those filenames have spaces in them.
gs -dPDFX -dNOPAUSE -dBATCH -dNOOUTERSAVE -sDEVICE=pdfwrite -sOutputFile="${filename}" -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dCompatibilityLevel=1.4 "${f}" /usr/local/share/ghostscript/9.20/lib/PDFX_def.ps
If the filename has a space, then GS says "no such file", giving the name as:
path/to/file/partial\
(Note the final backslash.)
I'm also getting:
Error: /undefinedfilename in (/Users/Ben/Desktop/qwe\\ qwe.pdf)
where it's taking the escape literally. I can't believe such a venerable piece of software has such a major failing, though others seem to have had the same problem, without any significant solution. Is there anything I can do to my script?
I'm on MacOS 10.11 and 12. Oh and "don't have spaces" is not a solution. ;-)
UPDATE: Even the very simplest example shows the error:
> f="/Users/Ben/Desktop/qwe\ qwe.pdf"
> gs "$f"
GPL Ghostscript 9.20 (2016-09-26)
Copyright (C) 2016 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefinedfilename in (/Users/Ben/Desktop/qwe\\ qwe.pdf)