实例详解shell中$和$@的区别
发布时间:2014-12-09 编辑:jiaochengji.com
本文介绍下,shell编程语言中$与$@的区别,分享一个完整的示例代码,深入探讨下二者的区别,有需要的朋友参考下。
本节内容:
shell中$和$@的区别
例子:
复制代码 代码示例:
#!/usr/bin/bash
#site: www.jiaochengji.com
#
E_BADARGS=65
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` argument1 argument2 etc."
exit $E_BADARGS
fi
echo
index=1
for arg in "$*"
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as single word."
echo
index=1
for arg in "$@"
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as seperated words."
echo
index=1
for arg in $*
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as seperated words."
echo
index=1
for arg in $@
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as seperated words."
exit 0
#site: www.jiaochengji.com
#
E_BADARGS=65
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` argument1 argument2 etc."
exit $E_BADARGS
fi
echo
index=1
for arg in "$*"
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as single word."
echo
index=1
for arg in "$@"
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as seperated words."
echo
index=1
for arg in $*
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as seperated words."
echo
index=1
for arg in $@
do
echo "Arg #$index = $arg"
let "index+=1"
done
echo "Entire arg list as seperated words."
exit 0
执行结果:
复制代码 代码示例:
$ ./test.sh bi yutong
Arg #1 = bi yutong
Entire arg list as single word.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words
Arg #1 = bi yutong
Entire arg list as single word.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words.
Arg #1 = bi
Arg #2 = yutong
Entire arg list as seperated words
以上通过示例,介绍了shell中$和$@的区别,希望对大家有所帮助。
您可能感兴趣的文章:
inux shell初级入门教程
实例详解shell中$和$@的区别
了解bash与sh中的export语法的区别
shell 求字符串长度的方法
python shell是什么
source命令执行shell文件与shell script文件名直接运行的区别
深入解析tcsh的初始化配置文件
shell条件测试语句实例-测试apache是否开启
Linux Source命令解析
shell按行读取文件的三种方法
上一篇:删除目录下的指定文件的shell脚本
下一篇:linux shell编程知识点总结
[关闭]