Home > Archive > AWK > May 2005 > OT: Re: command-line vs. script file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
OT: Re: command-line vs. script file
|
|
| Ed Morton 2005-05-18, 3:57 am |
|
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
| |
| Kenny McCormack 2005-05-18, 3:57 am |
| In 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.
| |
| Chris F.A. Johnson 2005-05-18, 3:57 am |
| On 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>
| |
| Ed Morton 2005-05-18, 3:57 am |
|
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.
|
|
|
|
|