Linux shell 命令行參數

                                                                 Linux shell 命令行參數shell

    $數字的用法 ($0除外)bash

#!/bin/bash
#test $ useful
value=$1
echo $value     
//寫法
./test$ 10 
10

    $# 用法this

#!/bin/bash
#test $ useful
value=$# //參數的數量
echo $value 
//用法
[root@CentOS tmp]# ./test$ 10 20 230
3

     $# 特殊用法,直接獲取最後一個值spa

#!/bin/bash
#test $ useful
echo ${!#} //{}中用感嘆號替代$
//用法
[root@CentOS tmp]# ./test$ 10 20 230
230

    $* 用法(不過奇怪的是 $@ 的功能變成如出一轍了)命令行

#!/bin/bash
#test $ useful
for s in $*
do
echo $s
done
echo "this \$* is $* "
//用法
[root@CentOS tmp]# ./test$ 10 20 230
10
20
230
this $* is 10 20 230
相關文章
相關標籤/搜索