Chapter 7
Special Variables
Most programming languages have special variables. These might be referencing data from outside the program, or data from a command line, or even referencing data defined as part of the language itself. We will investigate many of these special variables later, for now we are going to focus on getting data from the command line.
What do we mean ‘get information from the command line’?
When a command is entered on the command line it starts with the command (in this case the program we want to run) and is often followed by one or more arguments that changes the way the command works. For example, if we enter ls at the bash command prompt we see the list of files and directories in the current directory. If we enter ls .. the two dots tell the ls command to list the files and directories in the parent directory to the current one. The .. is a value provided to the ls program as a ‘command line argument’.
Now we will change our program to use some information from the command line and greet the user by name.