Command-Line Arguments

You have already seen several scripts using command-line arguments. As a script is started, the initiating shell searches for extra data on the command line. Anything beyond the script name is treated as a command-line argument and is placed in shell variables. The shell variables used for command-line storage are named $1 (first argument), $2 (second argument), and so on. These are also referred to as positional parameters because the position of the argument determines the name of the shell variable into which it is placed. Table 8.1 provides a list of the positional and special parameters available to you within your shell script.

Table 8.1. Positional and special parameters
Parameter Meaning
0 Name of script, shell, ...

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.