Implementation principle and code example of Linux shell passing parameters


Shell pass parameters

When executing shell script, we can pass parameters to the script. The format of parameters obtained in the script is $n. N represents a number, 1 is the first parameter to execute the script, 2 is the second parameter to execute the script, and so on

In the following example, we pass two parameters to the script and output them respectively, where $0 is the file name to execute:

Special character parameters

$# the number of arguments passed to the script

$* displays all parameters passed to the script as a single string, such as “1 2 3”

$$the current process ID number of the script running

$! The ID number of the last process running in the background

[email protected] displays all parameters passed to the script as multiple strings, such as “1” “2” “3”

$- displays the current options used by the shell, andSet commandIt has the same function.

$? Displays the exit status of the last command. 0 indicates no error, any other value indicates an error.

The difference between $* and [email protected]


The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.