在许多 Stack Overflow 问题和 Bash 教程中,我看到可以通过两种方式访问 Bash 脚本中的命令行参数:
$ ~ >cat testargs.sh
#!/bin/bash
echo "you passed me" $*
echo "you passed me" $@
导致结果是:
$ ~> bash testargs.sh arg1 arg2
you passed me arg1 arg2
you passed me arg1 arg2
$*
和 $@
有什么区别?
何时应使用前者,何时应使用后者?
echo "something $@"
视为错误。 - Alex Cohn