linux $* 和$@ if [ ](字符串比较)

$* 将命令后面的参数理解为一个类似为字符串,$@理解为多个单个的参数,类似理解成数据  $#参数总数

[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为非空时为真

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值