Get parameter from shell $n n is a number n=1 (The first parameter to execute shell ) n=2 (The second parameter to execute shell )
#!/bin/bash# author:kekeecho"Shell pass parameter~"echo"Executed file name: $0"echo"The first parameter is: $1"echo"The second parameter is: $2"echo"The third parameter is: $3"
parameter
description
$#
The number of the parameters passed to the shell
$*
Display all the parameters passed to the shell with a single string
``$$
Current process id of the running shell
$!
id of the last process running in the background
$@
Same with $*, use with""
$-
Display the current options used by the shell
$?
Display the exit status of the last command. 0 means no error
#!/bin/bash# author:kekeecho"Shell pass parameter~"echo"Executed file name: $0"echo"The first parameter is: $1"echo"The second parameter is: $2"echo"The third parameter is: $3"echo"The number of the parameters: $#"echo"Use \$* to Display all the parameters passed to the shell with a single string: $*"echo"Use \$@ to Display all the parameters passed to the shell with a single string: $@"echo"See difference between --\$*-- and --\$--"echo"Display with --\$*--"for i in "$*";doecho$i
done
echo"Display with --\$@--"for i in "$@";doecho$i
done