Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 13: Handling User Input > Special Parameter Variables

Special Parameter Variables

There are a few special variables available in the bash shell, which track command line parameters. This section describes what they are, and how to use them.

Counting Parameters

As you saw in the last section, it's often a good idea to verify command line parameters before using them in your script. For scripts that use multiple command line parameters, this can get tedious.

Instead of testing each parameter, you can just count how many parameters were entered on the command line. The bash shell provides a special variable for this purpose.

The special $# variable contains the number of command line parameters included when the script was run. You can use this special variable anywhere in the script, just like a normal variable:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint