

Obviously some of these are more readable than others. The following all work:- $ ls Library/'Application Support' $ ls Library/Application' 'Support $ ls Libr'ary/Application Su'pport The shell is surprisingly lenient about where you can place the quotes. And then, internally, it removes the quotes so they are not part of the argument, leaving only the characters between the quotes. When the shell sees a string of characters enclosed in quotes, it ignores any spaces or other special characters inside it and treats it as a single argument. These work because the whole path is enclosed in a quoted string which tells the shell not to split it up.

The first is to use single or double quotes:- $ ls “Library/Application Support” There are two ways to alleviate this problem. And ls of course tried to list the contents of both directories. That’s because the shell interpreted the space in the path as a separator, and it therefore assumed there were two arguments, Library/Application and Support, which it duly sent to the ls command. If you try this you’ll get, not one, but two error messages! ls: Library/Application: No such file or directory ls: Support: No such file or directoryĬan you see what’s happening here? The error messages both originate from the ls command and they are saying it can’t find either the Library/Applications or the Support paths. For example, you might want to list the contents of the Application Support subdirectory:- $ cd ~ $ ls Library/Application Support What if the path contains spaces? It’s not a hypothetical situation: on macOS, there’s a directory in home called Library, and inside that there are quite a few subdirectories with spaces in their names. (For the purposes of this discussion I’m going to ignore command line options.) That’s a simplified general form of the command line. Then it considers the first unbroken string of characters to be the command, and every subsequent string to be an argument to the command, like this:- $ command argument1 argument2. When you press return the shell starts parsing the command line and one of the first things it does is to split up the command line at each space. An argument just means a bit of information you want to pass to the command.Ĭommand line arguments are separated from the command, and from each other, by spaces. It has nothing to do with arguing, it’s simply a mathematical term that harks back to the days when most computer programs were written by mathematicians. When you specify a path after a command like this, the path part is called a command line argument. In the macOS Terminal or any Linux/Unix shell, a common command line might look like:- $ ls path The Problem of Spaces On the Command Line
