start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 8.15 Differences Between Bourne and C Shell Quoting Chapter 8
How the Shell Interprets What You Type
Next: 8.17 verbose and echo Variables Show Quoting
 

8.16 Quoting Handles Special Characters in Filenames

If you want to work with files that have spaces or special characters in the filenames, you may have to use quotes. For instance, if you wanted to create a file that has a space in the name, you could use the following:

/dev/null 
% cp /dev/null 'a file with spaces in the name'

Normally, the shell uses spaces to determine the end of each argument. Quoting (8.14, 8.15) changes that - for example, the above example only has two arguments. You can also use a backslash (\) before a special character. The example below will rename a file with a space in the name, changing the space to an underscore ( _ ):

% mv a\ file a_file

Using the same techniques, you can deal with any character in a filename:

% mv '$a' a

At worst, a space in a filename makes the filename difficult to use as an argument. Other characters are dangerous to use in a filename. In particular, using ? and * in a filename is playing with fire. If you want to delete the file a?, you may end up deleting more than the single file.

- BB


Previous: 8.15 Differences Between Bourne and C Shell Quoting UNIX Power ToolsNext: 8.17 verbose and echo Variables Show Quoting
8.15 Differences Between Bourne and C Shell Quoting Book Index8.17 verbose and echo Variables Show Quoting

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System