$# 是传给脚本(或者函数)的参数个数, $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

 

相关文章:

  • 2021-12-19
  • 2021-12-19
  • 2022-02-19
  • 2022-12-23
  • 2021-12-19
  • 2021-12-29
  • 2021-12-19
  • 2021-12-19
猜你喜欢
  • 2021-12-19
  • 2021-12-19
  • 2021-10-28
  • 2021-12-19
  • 2021-12-19
  • 2021-08-23
  • 2021-09-04
相关资源
相似解决方案