Bash / ssh / scp quoting problem...

Robert Heller heller at deepsoft.com
Thu Feb 11 14:23:04 UTC 2021


I have a script to convert document files.  I have the conversion software on 
one machine but sometimes have the files on another.  Sometimes the filenames 
have pesky shell meta characters (dreaded spaces -- thank you Steve Jobs).

I have a bash script that uses scp and ssh to do the work:

#!/bin/bash -v
scp "$1" sauron:/extra/
base=`basename "$1"`
broot=`basename "$base" .doc`
if [ "$broot" = "$base" ]; then
  broot=`basename "$base" .docx`
fi 
ssh -X -Y sauron /usr/bin/doc2pdf -v "\"/extra/$base\""
f1="/extra/${broot}"
ssh sauron ls -l "\"$f1\".*"
scp sauron:"\"$f1\".pdf" /scratch/

The problem is the last line. I cannot figure out how to quote it properly.  
Scp gives an error:

gollum% procs/doc2pdf.sh /scratch/Wendell\ Newsletter\ SEPT\ 2020.docx
#!/bin/bash -v
scp "$1" sauron:/extra/
Wendell Newsletter SEPT 2020.docx             100%  235KB   2.0MB/s   00:00    
base=`basename "$1"`
broot=`basename "$base" .doc`
if [ "$broot" = "$base" ]; then
  broot=`basename "$base" .docx`
fi 
ssh -X -Y sauron /usr/bin/doc2pdf -v "\"/extra/$base\""
func=xmlSecCheckVersionExt:file=xmlsec.c:line=188:obj=unknown:subj=unknown:error=19:invalid version:mode=abi compatible;expected minor version=2;real minor version=2;expected subminor version=25;real subminor version=26
Selected output format: Portable Document Format [.pdf]
Output file: file:///extra/Wendell%20Newsletter%20SEPT%202020.pdf
Input file: /extra/Wendell Newsletter SEPT 2020.docx
f1="/extra/${broot}"
ssh sauron ls -l "\"$f1\".*"
-rw-r--r--. 1 heller users 240993 Feb 11 09:16 /extra/Wendell Newsletter SEPT 2020.docx
-rw-r--r--. 1 heller users 199038 Sep 22 08:28 /extra/Wendell Newsletter SEPT 2020.html
-rw-r--r--. 1 heller users 246869 Feb 11 09:16 /extra/Wendell Newsletter SEPT 2020.pdf
scp sauron:"\"$f1\".pdf" /scratch/
protocol error: filename does not match request

It is clear that somehow the filename is not being passed over properly, but I 
cannot figure out how to quote it and still evaluate the variable. The line 
above seems to work properly.

And don't tell me to install the conversion code on the local machine.  That 
would like telling me I should not have more than one computer on my LAN.

-- 
Robert Heller             -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller at deepsoft.com       -- Webhosting Services
                                                                        




More information about the ubuntu-users mailing list