How to write in Terminal a path or expression that contains spaces - Unexpected argument

photo of author
stealth
Update:

In application Port, each character means something. It can be a small part of a code, a command line argument or part of a script. The "space" is not exempt from this feature of the Terminal either. A "space" typed in the Terminal in a command line argument, it will not be recognized as a space. Hence the error: Unexpected argument.

The simplest example is to use the tutorial in which we learn about how to change the default location (Desktop) to automatically save screen shots on macOS.

If we want the folder in which to save the screen shots to be "Screen Shots", then in the command line in the Terminal we will have to correctly define the argument for "space". Otherwise, after executing the command line we will meet her error.

Wonderland:

defaults write com.apple.screencapture location ~/Desktop/Screen Shots 


To define a space between two words in the command line argument, we will use the character "\"Immediately after the first word.

Correct command line:

defaults write com.apple.screencapture location ~/Desktop/Screen\ Shots


Attention, the command line contains spaces. This tutorial only applies to command line arguments that contain spaces. In our case, a folder of which name is composed of two written words unbound.

I am happy to share my experiences in the field of computers, mobile phones and operating systems, to develop web projects and to bring the most useful tutorials and advice. I like to "play" on the iPhone, MacBook Pro, iPad, AirPort Extreme and on operating systems macOS, iOS, Android and Windows.

Leave a Comment