shell中$*与$@的区别
来源:互联网 发布:mac dock栏隐藏 编辑:程序博客网 时间:2024/05/17 01:24
关于$* 和 $@的 一点 认识 同是菜鸟一起学习
$*
所有的位置参数,被作为一个单词.
注意:"$*"必须被""引用.
$@
与$*同义,但是每个参数都是一个独立的""引用字串,这就意味着参数被完整地传递,
并没有被解释和扩展.这也意味着,每个参数列表中的每个参数都被当成一个独立的
单词.
注意:"$@"必须被引用.
$@ $* 只在被双引号包起来的时候才会有差异
双引号括起来的情况:
$*将所有的参数认为是一个字段
$@以IFS(默认为空格)来划分字段,如果空格在“”里面,不划分。采用LS的脚本运行./test 1 "2 3" 4 来发现差异
没有括起来的情况是$@和$*一样的,见到IFS就划分字段。还是采用LS的脚本运行./test 1 "2 3" 4 来发现差异
[Copy to clipboard] [ - ]CODE:#!/bin/bash
echo
index=1
echo "Listing args with\"\$*\":"
for arg in "$*"
do
echo "Arg #$index=$arg"
let "index+=1"
done
echo "所有的参数被认为是一个单词"
echo
index=1
echo "Listing args with \"\$@\":"
for arg in "$@"
do
echo "Arg #$index=$arg"
let "index+=1"
done
echo "所有的参数被认为是各个独立的单词"
echo
index=1
echo "Listing args with \$* (未被引用):"
for arg in $*
do
echo "Arg #$index=$arg"
let "index+=1"
done
echo "所有的参数被认为是各个独立的单词"
exit 0
运行后输出为
[Copy to clipboard] [ - ]CODE:[root@localhost ABS]# ./test 1 2 3 4
Listing args with"$*":
Arg #1=1 2 3 4
所有的参数被认为是一个单词
Listing args with "$@":
Arg #1=1
Arg #2=2
Arg #3=3
Arg #4=4
所有的参数被认为是各个独立的单词
Listing args with $* (未被引用):
Arg #1=1
Arg #2=2
Arg #3=3
Arg #4=4
所有的参数被认为是各个独立的单词
0 0
- shell中$*与$@的区别
- SHELL中&&与||的区别
- shell中$*与$@的区别
- shell中$*与$@的区别
- shell中$*与$@的区别
- shell中$@与$*的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$(( ))、$( )与${ }的区别
- shell中$*与$@的区别
- shell中" "(双引号)与 ' '(单引号)的区别
- shell中单引号与双引号的区别
- shell中$(( )) 与 $( ) 还有${ }的区别
- shell中$(( )) 与 $( ) 还有${ }的区别
- 8051存储区布局
- 浅谈JSP自定义标签实现过程
- 南方周末:采访万科总经理 郁亮
- A strange lift(解题报告)
- winsock,ws2_32,WinInet,WinHttp对比
- shell中$*与$@的区别
- android Tab与TabHost
- 错误 frm-40654 记录已经被另一个用户更新,重新查询以查看修改
- 工厂模式-简单工厂模式
- 基于暗通道的图像去雾算法_CVPR09 BestPaper_KaiMing He
- Winform调用风云二号卫星云图
- 我在IT职场打滚超过15年了,从小小的程序员做到常务副总。
- HDU-3912 Turn Right 简单搜索
- Opencv cvCanny 函数