Code Comments
Programming Forum and web based access to our favorite programming groups.Chris F.A. Johnson wrote: > On Sun, 15 May 2005 at 13:21 GMT, Ed Morton wrote: > > > > There's nothing wrong with "-" in a filename, except at the > beginning. Any time you have to say "except..." there is a problem. The POSIX portable filename standard allows letters, > numbers, periods, hyphens and underscores, but a name may not > begin with a hyphen. > We often write scripts that manipulate file names, holding parts of the name in variables, creating tmp file names from the parts, etc. so the impact of a hyphen isn't restricted to where it appears in the original file name. I agree you can later code to avoid the potential problems introduced by "-"s, but if you just choose to avoid them when creating the files then you don't need to deal with them at all. Ed
Post Follow-up to this messageIn article <ta6dnY-rs8WWHRrfRVn-1w@comcast.com>, Ed Morton <morton@lsupcaemnt.com> wrote: ... >We often write scripts that manipulate file names, holding parts of the >name in variables, creating tmp file names from the parts, etc. so the >impact of a hyphen isn't restricted to where it appears in the original >file name. Exactly. That's the point.
Post Follow-up to this messageOn Sun, 15 May 2005 at 16:59 GMT, Ed Morton wrote: > > > Chris F.A. Johnson wrote: > > Any time you have to say "except..." there is a problem. > > The POSIX portable filename standard allows letters, > > We often write scripts that manipulate file names, holding parts of the > name in variables, creating tmp file names from the parts, etc. so the > impact of a hyphen isn't restricted to where it appears in the original > file name. > > I agree you can later code to avoid the potential problems introduced by > "-"s, but if you just choose to avoid them when creating the files then > you don't need to deal with them at all. When is a hyphen a problem, except at the beginning of a filename? -- Chris F.A. Johnson <http://cfaj.freeshell.org> ======================================== ========================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress <http://www.torfree.net/~chris/books/ssr.html>
Post Follow-up to this message
Chris F.A. Johnson wrote:
> On Sun, 15 May 2005 at 16:59 GMT, Ed Morton wrote:
>
>
>
> When is a hyphen a problem, except at the beginning of a
> filename?
>
As a trivial example:
$ file=a-b
$ tmp="${file#[a-z]}"
$ > $tmp
$ rm $tmp
rm: invalid option -- b
Try `rm --help' for more information.
Had I instead used underscores in the name of "file":
$ file=a_b
$ tmp="${file#[a-z]}"
$ > $tmp
$ rm $tmp
The hyphen was not at the start of the original file name but by
manipulation to produce a tmp file, it ended up at the front of the tmp
file name and so became a problem.
Regards,
Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.