Second Example: commands and parameters


1. Start the Terminal if it is not already running.


2. Type
sleep

in the Terminal window and press


3. The Computer prints:
usage: sleep seconds

Good. We made a mistake. And the computer did not explode, nor is all our data gone. People are often scared of making mistakes in the Terminal. In the GUI those pretty Windows give you the sense that all is still alright, even after you did the wrong thing. The Terminal has a bad reputation for reacting bad when given inproper input. But that's not true: Here we recieved a clear hint what we can do to use the command. Give it a number of seconds. Let's try that.

4. Type
sleep 3

last time it's mentioned here that you have to press after a command


What happened? The cursor jumped to the next line. Actually you pressing enter did that. And then nothing happened for 3 seconds. The sleep command does exactly that: It wait's. If you don't tell it how long, then it does tell you that it needs to know the number of seconds that it is supposed to wait.

Commands and Parameters
The number after the sleep is called a parameter. You needed to put at least one space between 'sleep' and the number. Since our language also uses spaces between words its easy to miss this important point. Your line of input that you entered is first split up into pieces. Those are separated by what is called 'whitespaces'. Mostly spaces or tabs. You can have as many whitespaces in a separator as you like. The first piece of the line is always the command. The rest of the line (or until a ';' sign, more on that later) are the parameters. These will be given to the command. It's up to the command to do something with them. When we started the sleep command first, we did not give it any parameters, and it reacted with the hint that it would like one. Other commands like 'date' in the first example, don't even need a parameter. It really depends. There are common standards, but it's up to the author of the command to process the parameters. Since Unix has millions of authors it is only somewhat consistent.


The Prompt
After the time is over you see a line again. Mine looks like:
Computer-Name:~ andreas$
But yours looks different. This is called the prompt. If the computer prints the prompt then it tells you that you can enter the next command. This was very important when computers where much slower. Most commands return instantly today. Like almost anything in the Terminal you can reconfigure the prompt to anything you like. But that comes later.

You might have expected for your Mac to go to sleep after you entered 'sleep' in the mighty Terminal. That would make sense. But The Terminal is old, very old. When the sleep command got introduced computers could not go to sleep. They were either on or off. And moving them between these two states was a big enterprise involving couple of guys (no women around computers back in the day) in long white coats.
When Apple started to run Unix the name 'sleep' for a command was already taken. Command names are much like domain names on the internet. Since everybody excepts the existing ones to stay there, new ones have to find their own words.
As it turns out there is no premade way to put the Mac to sleep from the terminal. But sure enough, somebody was so kind to take this information and made it available. That's nice.







feedback