$* 将命令后面的参数理解为一个类似为字符串,$@理解为多个单个的参数,类似理解成数据 $#参数总数
[root@mini0 test]# ./test4.sh jskd sj21 2 2 1 34 Using the $* method :jskd sj21 2 2 1 34 Using the $@ method :jskd sj21 2 2 1 34 ------------------------------ $* parameter # = jskd sj21 2 2 1 34 $@ Parameter #count = jskd $@ Parameter #count = sj21 $@ Parameter #count = 2 $@ Parameter #count = 2 $@ Parameter #count = 1 $@ Parameter #count = 34 [root@mini0 test]#
#!/bin/bash #testing $* and $@ echo "Using the $* method :$*" echo "Using the $@ method :$@" echo ------------------------------ for param in "$*" do echo "$* parameter #$count = $param " count=$[ $count + 1 ] done count=1 for param in "$@" do echo "$@ Parameter #count = $param" count=$[ $count + 1 ] done ~
if [ str1 = str2 ] 当两个串有相同内容、长度时为真
if [ str1 != str2 ] 当串str1和str2不等时为真
if [ -n str1 ] 当串的长度大于0时为真(串非空)
if [ -z str1 ] 当串的长度为0时为真(空串)
if [ str1 ] 当串str1为非空时为真