シェルスクリプトの$ @と$ *

@ 和 @和 @*の違い

#!/bin/bash

# $@ and $* 

my_fun (){
    
    

    echo "$#"

}



echo 'the number of parameter in "$@"   is'    $(my_fun  "$@")
echo 'the number of parameter in "$*"     is'     $(my_fun  "$*")

echo 'the number of parameter in $@      is'    $(my_fun  $@)
echo 'the number of parameter in $*        is'     $(my_fun  $*)
[lf@x201t ~]$ sh a.sh p1 "p2 p3" p4

the number of parameter in "$@" is 3  
the number of parameter in "$*" is 1

the number of parameter in $@ is 4
the number of parameter in $* is 4

違いがわかりますか?キー$ @の方が信頼性が高い

おすすめ

転載: blog.csdn.net/qq_22648091/article/details/108544894