当没有双引号时,$*和$@扩展为每个位置参数
出现在双引号中,"$*"扩展为将所有位置参数通过IFS(通常为空格)拼接为单个参数,而"$@"任然扩展为每个位置参数
1 2 3 4 5 6 7 8 9 |
#/bin/sh echo "------test for \$*--------" for x in $*; do echo "$x---"; done echo "------test for \"\$*\"--------" for x in "$*"; do echo "$x---"; done echo "------test for \$@--------" for x in $@; do echo "$x---"; done echo "------test for \"\$@\"--------" for x in "$@"; do echo "$x---"; done |
./test.sh hello javacoder.cn
------test for $*--------
hello---
javacoder.cn---
------test for "$*"--------
hello javacoder.cn---
------test for $@--------
hello---
javacoder.cn---
------test for "$@"--------
hello---
javacoder.cn---
Posted in: Linux
Comments are closed.