in reply to move command

In addition to what has been said already, I would like to point out that using an ampersand as a character in a filename (or a space, exclamation mark, \0, @ and similar special characters), while technically not forbidden, should be avoided. This is just begging for trouble sooner or later. Restrict yourself to [-A-Za-z0-9_.+%] when writing filenames, and you will be fine.

On second thought, maybe you should also drop [A-Z] from the list, in case your application needs to run on Windows as well...

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: move command
by JavaFan (Canon) on Jul 08, 2009 at 10:28 UTC
    Actually under all Unix filesystems I'm aware off, \0 is one of two characters that is forbidden in a filename. The other is the slash off course.

    Having said that, I fully agree with the advice to restrict the characters. Typically, I only use ASCII letters, digits, underscores, dashes and dots.

Re^2: move command
by ikegami (Patriarch) on Jul 08, 2009 at 16:20 UTC
    "+" and "-" should be avoided as the lead character. % is the var sigil used by the Windows shell (e.g. echo %PATH%, echo %1, etc). On second thought, maybe you should also drop

    in case your application needs to run on Windows as well...

    huh? Windows has no problems with lowercase letters, digits, underscores, and fewer problems than unix with the dash.

      Windows has no problems with lowercase letters

      Unfortunately it does. Try to create a file "FOO.TXT", and then create a new file "foo.txt". You will find that the second file "replaces" the first one. The reason is that Windows internally does not distinguish between lower and upper case. Well, this applies to Windows until XP. I don't know whether this has been fixed in Vista.

      and fewer problems than unix with the dash

      Partially true. Strictly speaking, Unix has no problem with dash, but you likely mean that the vast majority of Unix command line tools use the dash to denote switches, while the majority of Windows command line tools use a slash to denote a switch. Since there are still quite a few Windows utilities which also use a hyphen to denote a command line switch, you should avoid on Windows files starting with either a hyphen or a slash, while on Unix you will have a happier life if you don't have files starting with a hyphen, and a slash is ruled out as valid character anyway.

      Underscores, AFIK, are no problems in either OS. In Windows, there are some characters which you should avoid, since they have special meaning to the shell: caret (^), percent (%), double quotes ("), parentheses. Caret and percent are fine on Unix, but the others are better avoided there too. While Unix itself is tolerant on most characters, many of the shells on Unix have their own special characters, such as a tilde (~) on the starting position, or a $ sign.

      On Unix, I try to avoid characters which are special to the most common shells (bash, zsh, tcsh), not because it would be strictly necessary, but because it makes life easier. Given that at least tcsh is available on Windows as well - though it seems to be much less in use than on Unix -, I avoid these characters on Windows too.

      -- 
      Ronald Fischer <ynnor@mm.st>

        What you seem to be missing is while Windows is case-insensitive, it does remember the case of the name. If you create FOO.TXT, it will show up as FOO.TXT in a directory listing. If you create foo.txt, it will show up as foo.txt. Your suggestion would limit me to creating uppercase file names and that would be awful.

        You will find that the second file "replaces" the first one

        Not quite. The first file will be truncated, but its name will still be FOO.TXT, not foo.txt.