Shell Problem with the name of the files

Hello guys,

As you well know if a file/folder name contains a space (for example it has been created on a windows machine), there are some problem if you transport it on a unix OS.

EXAMPLE.
A USB stick has a folder named: New York and inside it are several photos: photo 1, photo 2, photo 3, .....
Is a way to open the folder New York ? ----> cd New York doesn't work

QUESTION.
Can you tell me please if the problem has solution ?
Is there not other solution than modify names using a Windows OS ?

Thanks very much.
 
These both work
Hello,
wonderfull.
Please, is there also a solution for names containing the accent mark ? I've seen that it transforms in a question mark.

Again: do you know if is there a way to set the alphabet of the vi editor?
To avoid for example that a new line (return carriage) is visualized as M ?

etc, etc, etc, .........

Thanks very much.
 
The problem of special characters (of which space is only one example) in file names is awful, and causes lots to hassles. It can be solved, but the solution requires being very careful and thorough.

To begin with: File names are not character strings that have the semantics of an encoding (such as UTF-8 or ISO8859-2), but are arrays of bytes. End users have to be careful to be consistent in their use of encodings: If you create a file (write the file name) using a UTF-8 name, then please do not look at the directory (read the file name) using an ISO encoding; you will see something that is "wrong" and confusing. My suggestion is to always use UTF-8, consistently in all applications.

File names can contain any byte other than "/" and NUL. As you said, spaces in file names are bad. Other characters are actually worse: newlines are very amusing (the output of ls becomes completely garbled), and other special characters can be better or worse. For example, it is legal to create a file whose name is the ANSI escape sequence for "print everything in blue", and then when doing ls, all text afterwards will be blue. More amusing is a file whose name is the escape sequence for "clear screen". The only defense against such things is discipline: Doctor, it hurts when I do this ... then just stop doing it. Personally, I try to avoid file names with spaces in them (but grudgingly allow them, they are just too useful), and non-printable special characters are completely out. My backup software warns me if it finds any file names that have characters outside of the range 0x21-0x7E, if they start with a minus sign, or contain a "#" sign (which many scripting languages take to mean "beginning of comment"), and when I see these warning, I clean up after myself.

If you process file names using "real programming languages" (perl, python, C++, ...), all this is not really a big problem, since all of these languages have a concept of a well-defined string, and strings can contain special characters. The real pain comes in shells, which are used both interactively and as shell scripts (which are really programs written in a pedestrian language). In interactive use, both quoting and escaping works, as pointed out above: cd New\ York or cd "New York". In scripts, only quoting is sensible. And there one has to be careful, and learn the quoting rules of the shell one is using: If $a is a variable that contains special nonsense (like quotes, dollar signs, and backticks), then '$a' and "$a" probably will work differently. I'm too lazy to look up the general rules and teach them right now, but from vague memory: in sh- and bash-scripts the single quote '$a' prevents expansion of nearly all special characters inside, while the double quote "$a" does not; but please read the documentation carefully before relying on that.

Lastly: I know nothing about vi. In emacs, you can set various line end modes to automatically suppress visualizing the carriage return (^M) at the end of the line; that is typically called DOS mode. But be careful: Just because you can't see the ^M doesn't mean it is not actually there.
 
Normal emacs runs fine on the console. Only problem is (at least in the US): the "delete" key (the bigger key at the top right) by default emits backspace, which emacs interprets as Control-H, and that runs the "help" function, instead of deleting a character. That can be fixed by switching keymaps, or one can learn to live with it.

If your system does not have X windows installed, you should install the "emacs-nox" package; the regular emacs package pulls in a lot of X-windows dependencies.
 
Back
Top