The meaning of the Linux variable parameter $

  
                

In Linux, many people don't understand the meaning of the variable parameter $ in the script, $0, $1. . . . . . What do you mean by each? The following small series will give you a detailed introduction to the meaning of the Linux variable parameter $, interested friends may wish to understand.

Let's write a simple script, to explain the significance of each variable after the execution # touch variable # vi variable script reads as follows: #! /bin/shecho “number:$#”

echo “scname:$0”

echo “first :$1”

echo “second :$2”

echo “argume:$@”

echo “show parm list:$*”

echo “show process id:$ $”

echo “show precomm stat: $? ”

Save Exit Give script execution permission # chmod +x variable Execute script # . /variable aa bbnumber:2

scname:. /variable

first:aa

second:bb

argume:aa bbshow parm list:aa bb

show process id:24544show precomm stat:0

By showing the results you can see: $# is the number of arguments passed to the script $0 is the name of the script itself $1 is the first argument passed to the shell script $2 is the first passed to the shell script The two parameters $@ are a list of all the parameters passed to the script. $* displays all the parameters passed to the script as a single string. Unlike the position variable, the parameter can exceed 9 months. The current process ID number of the script is running. $? Is to display the exit status of the last command, 0 means no error, others indicate an error

The above is the introduction of the meaning of the Linux variable parameter $, it can be seen that the variable parameter $ plus the number represents different in the script Meaning, how do you learn how to use the variable parameter $?

Copyright © Windows knowledge All Rights Reserved