cURL / Mailing Lists / curl-users / Single Mail

curl-users

RE: More whitespace escaping commandline

From: Rasmus Olsen <raol_at_envision.dk>
Date: Thu, 3 Apr 2014 21:38:31 +0000

Hi world,

I've finally found the solution after reading "White shell" article by Tomasz Wyderka <http://www.cofoh.com/white-shell>. My problem is exactly what Tomasz deals with in the end of the article.

The solution is to single-quote the variables in the double-qouted assignment, and do an eval. Like so:
------------------------------------------------
#!/bin/sh
CMD="curl -s -f --show-error --ftp-create-dirs -T '$1' -u '$2':'$3' '$4'"
eval $CMD 2>&1
if [ $? != 0 ]; then {
    echo "Houston we have a problem";
    exit 1;
} fi
echo 0
------------------------------------------------

I've tested the script with great succes :-)

Alex and Leif: Thanks for you suggestions - much appreciated! Unfortunately it won't work. Earlier today I tried everything I could think of including double quoting and escape-encoding the passed variables.

Best wishes,
Rasmus

________________________________
From: Rasmus Olsen
Sent: 03 April 2014 16:09
To: curl-users_at_cool.haxx.se
Subject: More whitespace escaping commandline

Hi,

I need a little kick in the right direction. Been fiddling with this whitespace escape problem all day to no avail.

I'm trying to automate FTP uploads of files like this (notice lots of whitspace):

"/Users/gmg/Library/Application Support/Enfocus/Switch Server/backing/DS_DeliverLowres/automanaged/route to#1/_00016_test.pdf"

It works fine when I manually upload this file using curl from the terminal and quote the filepath:

curl -s -f --show-error --ftp-create-dirs -T "/Users/gmg/Library/Application Support/Enfocus/Switch Server/backing/DS_DeliverLowres/automanaged/route to#1/_00016_test.pdf" -u username:password ftp://myserver/subfolder/

But the filepath is not escaped (at least not properly) when calling my script with the same quoted filepath:

gmg$ ./test.sh "filepath with whitespace" username password ftp://myserver/subfolder/

And this is the script:
------------------------------------------------
#!/bin/sh
CMD="curl -s -f --show-error --ftp-create-dirs -T $1 -u $2:$3 $4"
$CMD 2>&1
if [ $? != 0 ]; then {
    echo "Houston we have a problem";
    exit 1;
} fi
echo 0
------------------------------------------------

Can you help out a friend in need :-)

Best wishes,
Rasmus

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-04-03