Filename Trouble
Spaces in filenames can cause some pesky problems. But there are workarounds.
Over the years, Linux and Unix cognoscenti haven’t used spaces in file and directory names. Instead of naming a directory My Pictures, you’d name it My_Pictures, my.pictures, or mypix. Why? Shells break a command line at spaces, and most shells also word-split the results of variable and command substitution. So a filename containing spaces can be split into pieces.
Shells also assign a meaning to most non-alphabetic characters. A file named odds&ends or cool!! can cause trouble if you aren’t paying attention.
Applications that don’t get filenames from a shell don’t have these restrictions. So, Windows and Mac OS users — and users of graphical applications on Linux, too — can cause filesystem havoc for shell users.
What’s a guru to do? This month, let’s see what’s behind the problems and find some workarounds.
Parsing Problems
Each shell command-line — read from a shell prompt or a shell script — is parsed into words and other tokens, such as redirection symbols. By default, words are separated by whitespace: space, tab, and newline characters.
But whitespace characters are legal in filenames. If you’re trying to remove a file named old report.txt this way, watch out:
$ rm old report.txt
rm: cannot remove `old’…
rm: cannot remove `report.txt’…
The shell broke the command-line into three words and passed two arguments to the rm utility: old and report.txt.
Other non-alphabetic characters have their own special meanings to the