码迷,mamicode.com
首页 > 系统相关 > 详细

linux $* 和$@例子

时间:2018-11-05 19:10:24      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:done   lin   span   class   https   bsp   echo   -bash   linux   

参见ibm网站示例:

https://www.ibm.com/developerworks/cn/linux/l-bash-parameters.html

示例:

 

[ian@pinguino ~]$ type testfunc2
testfunc2 is a function
testfunc2 ()
{
    echo "$# parameters";
    echo Using $*;
    for p in $*;
    do
        echo "[$p]";
    done;
    echo Using "$*";
    for p in "$*";
    do
        echo "[$p]";
    done;
    echo Using $@;
    for p in $@;
    do
        echo "[$p]";
    done;
    echo Using "$@";
    for p in "$@";
    do
        echo "[$p]";
    done
}

 

执行如下:

 

[ian@pinguino ~]$ IFS="|${IFS}" testfunc2 abc "a bc" "1 2
> 3"
3 parameters
Using $*
[abc]
[a]
[bc]
[1]
[2]
[3]
Using "$*"
[abc|a bc|1 2
3]
Using $@
[abc]
[a]
[bc]
[1]
[2]
[3]
Using "$@"
[abc]
[a bc]
[1 2
3]

 

linux $* 和$@例子

标签:done   lin   span   class   https   bsp   echo   -bash   linux   

原文地址:https://www.cnblogs.com/wenxiao1-2-3-4/p/9910419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!