[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Escaping special characters for *nix file path

Subject: Re: Escaping special characters for *nix file path
From: Liam R E Quin <liam@xxxxxx>
Date: Sun, 29 Jul 2012 10:58:10 -0400
Re:  Escaping special characters for *nix file path
On Sun, 2012-07-29 at 15:58 +0200, Wolfgang Laun wrote:

> A relatively safe way would be to enclose the path name in apostrophes
> (') and escape all contained apostrophes and backslashes with a
> backslash.

It would be if it worked :-)

\ is not special inside '...' in the shell, and neither are ` or $
(in shell-speak, no interpolation happens and there is no escaping)

\ *is* special inside "..."
(this is the difference between the two forms of quote in fact)

so,
$ mkdir try
$ cd try
$ touch "a`date`b"
$ ls
aSun Jul 29 10:16:42 EDT 2012b
$ touch 'a`date`b
$ ls
a`date`b
aSun Jul 29 10:16:42 EDT 2012b
$ touch "c\`date\`d"
$ ls
a`date`b
aSun Jul 29 10:16:42 EDT 2012b
c`date`d
$

This is all about escaping from the shell, though. On Unix (and Linux
and OS X) a filename can contain any character except NUL (a zero byte)
or / (because that's the path separator).

If the resulting files are going to be accessed as URIs though, you also
have to avoid a ton of other characters, and \-escaping doesn't work -
you have to use uri-escape(), and in that case there's no need to mess
around with backslashes either.

But all this presupposes particular uses -- presumably XSLT is being
used to generate a shell script here.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Co-author, 5th edition of "Beginning XML", Wrox, June 2012

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.