shell中$@和$*的区别
2016-11-12 11:45
429 查看
$*
所有的位置参数,被作为一个单词.注意:“$*”必须被”“引用.
$@
与∗同义,但是每个参数都是一个独立的”“引用字串,这就意味着参数被完整地传递,并没有被解释和扩展.这也意味着,每个参数列表中的每个参数都被当成一个独立的单词.注意:”@”必须被引用.@* 只在被双引号包起来的时候才会有差异
双引号括起来的情况:
∗将所有的参数认为是一个字段@以IFS(默认为空格)来划分字段,如果空格在“”里面,不划分。采用LS的脚本运行./test 1 “2 3” 4 来发现差异
#!/usr/bin/env bash :<<EOF 运行结果如下: root@kali:~/.pyenv# /bin/bash asterisk_and_at.sh 1 2 3 4 5 "hello world" Listing args with "$*": Arg #1=1 2 3 4 5 hello world 所有的参数均认为是一个 Listing args with no double quoto $\*(没有被引用) Arg #1=1 Arg #2=2 Arg #3=3 Arg #4=4 Arg #5=5 Arg #6=hello Arg #7=world 所有的参数被认为是各个独立的单词 Listing args with "$\@": Arg #1=1 Arg #2=2 Arg #3=3 Arg #4=4 Arg #5=5 Arg #6=hello world Listing args with $\@(没有被引用): Arg #1=1 Arg #2=2 Arg #3=3 Arg #4=4 Arg #5=5 Arg #6=hello Arg #7=world EOF set -e #set -x index=1 echo "Listing args with \"\$*\": " for arg in "$*"; do echo "Arg #$index=$arg" let index+=1 done echo -e "所有的参数均认为是一个\n" index=1 echo "Listing args with no double quoto \$\*(没有被引用)" for arg in $*; do echo "Arg #$index=$arg" let index+=1 done echo -e "所有的参数被认为是各个独立的单词\n" index=1 echo -e "Listing args with \"\$\@\": " for arg in "$@"; do echo "Arg #$index=$arg" let index+=1 done echo index=1 echo "Listing args with \$\@(没有被引用): " for arg in $@; do echo "Arg #$index=$arg" let index+=1 done echo exit 0中
参考:http://blog.csdn.net/zhejiang9/article/details/7887569
相关文章推荐
- shell中$*与$@的区别
- shell中$*与$@的区别
- shell中$*与$@的区别
- linux系统中关于shell变量$*与$@的区别
- shell中$@和$*区别
- shell脚本中$@与$#区别
- 一个脚本实例浅析shell脚本中$@与$*的区别
- Shell特殊变量:$*和$@的区别
- shell中$*与$@的区别
- shell中$*与$@的区别
- shell中$@与$*的区别
- Linux Bash Shell $*和$@的区别
- shell中$*与$@的区别
- linux:Shell中exec、source和shell script的区别
- linux shell 管道命令(pipe)使用及与shell重定向区别
- Perl和Shell区别
- shell 单引号 双引号 反引号区别+反斜杠
- shell 和 Process 控制执行多个进程的区别
- shell中的反引号与$()区别
- shell环境变量以及set,env,export的区别