Calling kind geeks: Unix/OSX file naming question (re spaces)

Is there any way to render a space when using a Unix (in this case OSX, command line interface?

Eg if I have a folder called “Istara files” - how do I write that in Unix?

Istara files doesn’t work
Istara_files doesn’t work
Istara%20files doesn’t work

It may be that the only solution is to rename it Istarafiles, but I was hoping there was answer.

You have to “escape the shell” by enclosing the folder name in quotes, like mkdir “Istara files” or use the escape character (a backslash), like mkdir Istara\ files.

Oh brilliant! Thank you so much - putting " " around it did it perfectly!

This also works in a Windows cmd window. Although it can work without the quotes for certain commands, some programs will treat the filename as seperate arguments if quotes aren’t used.

There are other characters you have to do that with as well.

The only disallowed character is a front slash, since that is the path seperator. You usually have to escape the space, backslash, hash mark (#), ampersand, star (*), parenthesis, pipe (|), semicolon, angle brackets (< and >), backtick (`), tilde (~), double quote, and single quote characters. Keep in mind that you can’t escape the double quote with a double quote, so if you feel the need to make a filename with that character you have to use the backslash to escape it. You can, however escape the backslash with a preceding backslash.

Also, you can use the tab-completion to see how the shell does it. Type in part of a filename and press tab. If the shell can figure out what file you want, it will fill it in. If the shell has several candidates that match what you typed, it will show all the possibilities and beep, prompting you to fill in the rest. If the shell can’t find what you typed at all, it will beep without showing anything. If you do this to one of your space-containing filenames or other special character filenames, you will see where it escapes them with backslashes.

I should also add that you have to escape the question mark as well.

Note that a few shells do not support auto-completion. Bourne shell is the only one I can think of. I’ve never seen a Linux distro where it is the default, but it is in FreeBSD except for the superuser. The superuser uses csh, which will do auto-completion if there’s only one possibility, but will not print multiple possibilities. Bash will display multiple possibilities. Zsh will even let you toggle through the various possibilities if you repeatedly press tab. So it varies significantly.

Mac OS X, starting with 10.2, ships with bash as the default shell for all users.

Odd for what’s essentially a BSD, but MacOS X has never been the average BSD, now has it? :wink:

(Personally, I think more distros and OSes should move to zsh as the default shell. It’s bash-compatible, it has a hell of a lot more features without being bloated on today’s powerful machines, and it’s released under the same terms as bash (the GPL). It’s very much an evolutionary change, like going from sh to bash.)

Well I missed the fact that OS X was used in this example. For others though, it can’t be assumed that auto-completion will work with various unices.

“Istara Files”, ‘Istara Files’, or Istara\ Files all work :slight_smile:

What’s really fun is when you’re scripting shell commands from another environment that uses the same escape characters (e.g., AppleScript): to send an escape character you have to escape the escape!

Very helpful hint here: if you generally get rid of useless Windows icons (like the Command Prompt) icon, but still use the Start->Run command to start shells, note that in 2000 and XP, typing “command” no longer works properly. It’s correct to use “cmd” now. It took me two years (!!!) of frustration with not being able to escape or quote around anything before I found this out.

Cygwin is a good way to get bash (or tcsh, if you want) and a collection of other *nix command-line tools under Windows.

Wow. I had never even heard of “bash” before, and only vaguely heard of “shell” but didn’t specifically know what it was, other than a text way to use the internet.

Thanks all.

It has nothing to do with the Internet specifically. In Unix jargon, a “shell” is a textual, command-line interface to the operating system’s services. Even a machine unconnected to the Net will have a shell or two available. (Unless some mischievous person has deleted all the executables.)

More reading here.

From the BSD UNIX side, yes. From the MacOS X side, the only disallowed character is the colon (:), which was the path separator from the original MacOS System/Finder. I imagine the file system does some translating between the two automagically, though I’ve been too lazy to check. :wink:

The Finder changes front slashes to colons, and colons to front slashes. The Finder, or any other app, will never save a file whose true name contains a front slash. It’s impossible, as the low-level IO functions simply don’t work that way. They’ll intepret the slash as a subdirectory in which the file is being placed.

Oh is it ever! I have written an application at work that allows administrators to change the behavior of CGI programs via a CGI program. I have some routines where a CGI app takes info, makes a call to the shell to modify an existing CGI app which then has to generate dynamic output. You get great lines like

print "Hello World!\\\\\

Missing one backslash has some strange side effects.

It’s reserved on Linux, too, and Linux is not a BSD in any way. I can’t imagine it not being reserved on any Unix except one with a history as odd as MacOS X.

If that’s happened, you won’t even be able to login. (Yes, login is a seperate program. And due to the magic of one-way hashes, it does not need to know your actual password.)