On Fri, Dec 28, 2018 at 11:34 PM Jack Rosenthal <j...@rosenth.al> wrote:
>
> On Fri, 28 Dec 2018 at 23:09 -0500, David Storrs wrote:
> > I am using 'system' to offload some work onto wget and other
> > applications in a few one-off scripts.  Is there an easy way to escape
> > a string so it's suitable for usage in the shell?  Things like
> > backwhacking all the quotes and relevant spaces and such.
>
> Is avoiding the shell altogether an option? You could use "system*"

Not really:

Welcome to Racket v6.11.

; two argument strings
> (system* "/usr/local/bin/wget" "http://google.com"; "-O /tmp/fooflaksdjdghk")
 /tmp/fooflaksdjdghk: No such file or directory
#f

; one argument string
> (system* "/usr/local/bin/wget" "http://google.com -O /tmp/fooflaksdjdghk")
--13:47:10--  http://google.com%20-o%20/tmp/fooflaksdjdghk
           => `fooflaksdjdghk'
Resolving google.com -o ... failed: nodename nor servname provided, or
not known.
#f

Okay, it's transforming -O into -o.  Let's try the long form:

> (system* "/usr/local/bin/wget" "http://google.com"; 
> "--output-document=/tmp/zot")
...lots of spew...
#t

Yep, that works.  Okay, now let's try it with an actual filename,
unescaped to start.  I expect this to fail:

> (system* "/usr/local/bin/wget" "http://google.com"; 
> "--output-document=/tmp/Sara's birthday, 9/12/01-18/181")
/tmp/Sara's birthday, 9/12/01-18/181: No such file or directory
#f

Sure enough.  Oh good, we're back to shell-style escapes where all this started.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to