$@ and $* in shell scripts

@ Sum @ sum The difference between @ and *

#!/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

Do you see the difference? The key $@ is more reliable

Guess you like

Origin blog.csdn.net/qq_22648091/article/details/108544894