$: Gets the file name of the currently executing script, including the path.
[Root@test script]# Cat 0.sh
#!/bin/bash
echo $
[Root@test script]# SH 0.sh
0.sh
[Root@test script]# Cat 0.sh
#!/bin/bash
DirName "$"
BaseName "$"
[Root@test script]# sh/byrd/script/0.sh
/byrd/script
0.sh
$n: Gets The nth parameter of the current row's shell script, n=1..9, when n is 0, the file name of the script, if n is greater than 9, enclose the like${10} with braces.
[Root@test script]# Cat n.sh
#!/bin/bash
echo $ $ ${10}
[Root@test script]# sh n.sh a b c d e F g h i j k l m N
A B J
[Root@lamp script]# sh n.sh {a.. Z
A B J
[Root@test script]# sh n.sh ' seq 11 '
1 2 10
$*: Gets all the parameters of the current shell and treats all command-line arguments as a single string.
$@: All parameters of this program "$" "$" "$", which is the best way to pass parameters to other programs, so TA retains any whitespace embedded in each parameter.
$#: Gets the total number of arguments in the current shell command line.
[Root@test script]# cat hashtag.sh
#!/bin/bash
echo "$#"
[root@test script]# sh hashtag.sh
0
[Roo T@test script]# sh hashtag.sh 1 2 3
3
[root@test script]# sh hashtag.sh ' seq '
#
[Root@test script]# Cat example.sh
#!/bin/bash
#Example
If [$#-ne 2];then
echo Error, please enter two Parameters. "
exit 1
Else
echo "You did a good job."
fi
[root@test script]# sh example.sh a
Error, please enter two parameters.
[Root@test script]# sh example.sh a B
You did a good job.
[Root@test script]# sh example.sh a b c
Error, please enter two parameters.
$_: Represents the last parameter of the previous command
$$: The pid
[Root@lamp script]# cat dollar.sh
#!/bin/bash
echo "$$" >/tmp/dollar.pid
while True
do
 &N bsp; 1
Done
[root@lamp script]# sh dollar.sh
################################################< br> [Root@lamp ~]# cat/tmp/dollar.pid
1483
[root@lamp ~]# ps-ef |grep 1483
Root &nbs P 1483 1453 0 14:58 pts/1 00:00:00 sh dollar.sh
root 1532 1483 0 14:58 pts/1 00:00:00 sleep 1
root 1534 1496 0 14:58 pts/0 00:00:00 grep 1483
[root@lamp ~]# ps-ef |grep dollar
root & nbsp; 1483 1453 0 14:58 pts/1 00:00:00 sh dollar.sh
root 1555 1496 0 14:58 pts/0 00:00:00 grep dollar
$!: The PID that represents the last-executed background command
$?: A flag that represents the success of the previous command, or $ if the execution succeeds? is 0, otherwise not 0.
[Byrd@lamp script]$ pwd
/byrd/script
[Byrd@lamp script]$ echo $?
0 #运行成功
[Byrd@lamp script]$ Ls/root
Ls:cannot Open Directory/root:permission denied
[Byrd@lamp script]$ echo $?
2 #权限拒绝
[Byrd@lamp script]$ hahaha
-bash:hahaha:command not found
[Byrd@lamp script]$ echo $?
127 #未找到该命令
###########################################
[byrd@lamp ~]$ cat/byrd/script/question_mark.sh
#!/bin/bash
#Example
Ls-al/root >/dev/null 2>&1
If [$-eq 0];then
echo ' User is ro OT
Else
echo "The user is not root"
fi
[root@lamp script]# sh question_mark.sh
Us ER is root
[root@lamp script]# su-byrd
[byrd@lamp ~]$ sh/byrd/script/question_mark.sh
The user is not root
not completed, pending finishing!