opts=$@
getparam(){
arg=$1
echo $opts | xargs -n1 | cut -b 2- | awk -F '=' '{if($1=="'"$arg"'") print $2 }'
}
解释:
1. 脚本名称叫test.sh 入参三个: 1 2 3
运行test.sh 1 2 3后
$*为"1 2 3"(一起被引号包住)
$@为"1" "2" "3"(分别被包住)
$#为3(参数数量)
2. 在Unix Shell中,可以使用-n来判断一个string不是NULL值
[root]# export BB=
[root]# [ -n "$BB" ]
[root]# echo $?
1
3. 新建一个test1.txt,如下
557adfhg
bcd5464b
135465453456
233546576
[root@localhost shell]# cut -b 3- test1.txt
7adfhg
d5464b
5465453456
3546576
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31455969/viewspace-2138311/
,如需转载,请注明出处,否则将追究法律责任。