Shell脚本中的$类参数

$# 是传给脚本(或者函数)的参数个数, $0 是脚本本身的名字, $@ 是传给脚本(或者函数)的所有参数的列表. 举例:

cat foo.sh
#!/bin/bash

echo "script name   : $0"
echo "# of arguments: $#"
echo "all arguments : $@"
echo "arguments in order:"
for sArg in "$@"; do
    echo "  $sArg"
done
------------------------------------------------------------
./foo.sh aa bb cc
script name   : ./foo.sh
# of arguments: 3
all arguments : aa bb cc
arguments in order:
  aa
  bb
  cc
------------------------------------------------------------
; ./foo.sh aa "bb cc" dd
script name   : ./foo.sh
# of arguments: 3
all arguments : aa bb cc dd
arguments in order:
  aa
  bb cc
  dd

原文地址:https://www.cnblogs.com/ungshow/p/1432822.html