Ben Love on 21 Aug 2009 12:30:30 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] the character least likely to find in a Unix file name

* TuskenTower ( wrote:

> Someone decided the dollar sign was the least likely to find in a
> filename and produced the above code.  Another voiced concern over
> legibility and to stick to characters that don't require escaping.

The only characters guaranteed to never appear in a filename (on most
filesystems anyway) are the forward slash and the NUL (0).  Of course,
your path will have lots of legitimate forward slashes, so I'd argue
that NUL is really your only choice.  But your shell and/or sed might
choke on that.

The safest way might be to do it in multiple steps, and use some form of
C-style escaping.

1) Convert backslash to double-backslash.
2) Convert any delimeter characters to backslash+D.
3) Do your sed string with chosen delimiter.
4) Convert backslash+D back to delimeter.
5) Convert double-backslash back to backslash.

Of course, if you use sed to do the converts you're back at the same

Ben Love
blove+signature (at)  ||  ASCII ribbon campaign - ()           ||   against HTML e-mail  - /\

Attachment: signature.asc
Description: Digital signature

Philadelphia Linux Users Group         --
Announcements -
General Discussion  --