スクリプト-スクリプトパラメータの意味

1071 ワード

#!/bin/bash
# file name     : parameter.sh
# usage         : 

#     
echo "\$0: "$0
#     
echo "\$1: "$1
echo "\$2: "$2
#    "$1""$2""$3" 
echo "\$@: "$@
#    "$1c$2c$3",  c IFS      
echo "\$*: "$*
#               ,$@ $*   ,$*             ,       
echo "\$@: "$@
#   
echo "\$?: "$?


fname(){
 echo "function:\$0: "$0
 echo "function:\$1: "$1
 echo "function:\$2: "$2
 echo "function:\$@: "$@
 echo "function:\$*: "$*
 echo "function:\$@: "$@
 #            ,               ,   
 #        ,        ,  0        , 0    
 return 123
}

echo ------------------
fname p1 p2 p3
#          
echo "\$?: "$?

[root@localhost practice-sh]# ./parameter.sh 1,2 3 4 5 $0: ./parameter.sh $1: 1,2 $2: 3 $@: 1,2 3 4 5 $*: 1,2 3 4 5 $@: 1,2 3 4 5 $?: 0 ------------------ function:$0: ./parameter.sh function:$1: p1 function:$2: p2 function:$@: p1 p2 p3 function:$*: p1 p2 p3 function:$@: p1 p2 p3 $?: 123