4.1. Introduction

When working in a Unix-like environment, programs are launched when the user enters the program’s name into the shell (i.e., they type it in, then press RET). Many programs allow or even require the user to specify additional pieces of information, called command-line arguments, after the program’s name to adjust the program’s settings and supply values that the program needs to execute.

For example, consider using ls to list all of the entries in the ~/public_html directory. This is typically accomplished by supplying ~/public_html as a command-line argument:

ls ~/public_html
bookmarklets.html index.html

The ls program does not prompt the user for any input; however, it does support changing its behavior using additional command-line arguments. For example, the long listing output format is enabled when -l is included, and hidden files that begin with a dot . are listed alongside the other entries when -a is included:

The ls command with two command-line arguments: -l and ~/public_html.
ls -l ~/public_html
total 32
-rw-r--r--.  1 mepcott myid    2510 May  7  2023 bookmarklets.html
-rw-r--r--.  1 mepcott myid    2115 Sep 13  2022 index.html
The ls command with three command-line arguments: -l, -a, and ~/public_html.
ls -l -a ~/public_html
total 32
drwxr-xr-x.  7 mepcott myid     268 Feb 22  2024 .
drwx--x---. 44 mepcott apache  8192 Aug 27 16:04 ..
-rw-r--r--.  1 mepcott myid    2510 May  7  2023 bookmarklets.html
-rw-r--r--.  1 mepcott myid    2115 Sep 13  2022 index.html

Using command-line arguments instead of one or more user input prompts to adjust program behavior is a supported by most programs designed to run in a Unix environment.