bash中 $@ $* 详细解释
- $@ $* 没有" "包围时,两者无任何区别,将每个参数看作单独参数,当参数中使用' '或" "时会将其拆开,作为单独参数,因此,此种用法,可能曲解参数传递的本意
#!/bin/evn bash -u echo "print each parameter from \$*" for p in $* do echo $p done echo "print each parameter from \$@" for p in $@ do echo $p done
可以看到参数中的'd e'被拆开作为两个参数
- "$@" "$*" 当其被" "包含,"$*" 将所有参数当作整体,"$@" 每个参数独立,并且保留参数的结构
#!/bin/evn bash -u echo "print each parameter from \"\$*\"" for p in "$*" do echo $p done echo "print each parameter from \"\$@\"" for p in "$@" do echo $p done