参数传递
1. 顺序传参
参数名 | 作用 |
---|---|
$0 | filename |
$1/$2/$3 ….$n | 第n个参数 |
2. OPT
只能用单个字母
1#!/bin/bash
2
3while getopts ":n:a:h" optname; do
4 case "$optname" in
5 "n")
6 echo "get option -name, value is $OPTARG"
7 ;;
8 "a")
9 echo "get option -age, value is $OPTARG"
10 ;;
11 "h")
12 echo '
13 -n name of user
14 -a age of user
15 '
16 ;;
17 ":")
18 echo "No argument value for option $OPTARG"
19 ;;
20K "?")
21 echo "Unknow options $OPTARG"
22 ;;
23 *)
24 echo "Unknow error while processing options"
25 ;;
26 esac
27 echo "option index is $OPTIND"
28done
29
30echo "done"
j j