Shell脚本_位置参数和预定义参数

一、位置参数变量
 

1、输出两个输入参数之和 l1.sh

1
2
3
4
5
6
7
8
9
#!/bin/bash
 
num1=$1
num2=$2
sum=$((num1+num2))
 
# 输出num1+num2之和
 
echo $sum

调用:chmod 755 l1.sh

./l1.sh 4 5


2、输出输入参数的个数和值 l2.sh

1
2
3
4
5
#!/bin/bash
 
echo "所有参数个数:$#"
echo "所有参数:$*"
echo "所有参数:$@"



3、$*和$@的区别 l3.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
 
for i in "$*"
        do
          echo "\$\*的参数是:$i"
        done
 
 
for i in "$@"
        do
          echo "\$\@的参数是:$i"
        done
~                                                                                                                                                                                                          
~




二、预定义变量

 






posted @ 2016-10-11 10:35    阅读(5758)  评论(0编辑  收藏  举报