Chinaunix首页 | 论坛 | 博客
  • 博客访问: 752722
  • 博文数量: 130
  • 博客积分: 2951
  • 博客等级: 少校
  • 技术积分: 1875
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-04 18:32
文章分类

全部博文(130)

文章存档

2013年(1)

2012年(129)

分类: Python/Ruby

2012-02-14 16:38:53

getopt:
摘自AIX中/usr/sbin/bosboot:
  1. set -- `getopt ab:Dd:Ik:Ll:M:p:qT:v $*`

  2. if [ -z "$1" ]
  3. then
  4.     usage
  5.     exit 1
  6. fi

  7. while [ $1 != -- ]
  8. do
  9.     case $1 in

  10.         -a)    [ "$action" = y ] && {
  11.                 usage; exit 1
  12.             }
  13.             action=y;;
  14.         -b)    [ "$bootimage" ] && {
  15.                 usage; exit 1
  16.             }
  17.             bootimage=$2    # Boot image file name
  18.             [[ "$bootimage" != /* ]] && bootimage=`pwd`/$bootimage
  19.             dofile=y
  20.             shift;;
  21.         -d)    device=$2    # Target boot device
  22.             shift;;
  23.         -D)    [ "$dolld" ] && {
  24.                 usage; exit 1
  25.             }
  26.             dolld=-D;;    # Load kernel debugger
  27.         -I)    [ "$dolld" ] && {
  28.                 usage; exit 1
  29.             }
  30.             dolld=-I;;    # Invoke kernel debugger
  31.         -k)    kernel=$2    # Kernel file name
  32.             [[ "$kernel" != /* ]] && kernel=`pwd`/$kernel
  33.             shift;;
  34.         -M)    reqmode=$2        # Boot mode
  35.             shift;;
  36.         -L)    dolockinstr=-L;; # Enable MP locks instrumentation
  37.         -l)    blvdev=$2    # Target boot logical volume
  38.             # Ensure lv is of type boot
  39.             QSTR="name=${blvdev##*/} and attribute=type and value=boot"
  40.             lvtype=`ODMDIR=$ORIGIN odmget -q"$QSTR" CuAt`
  41.             [ -z "$lvtype" ] && error_func 4 $blvdev
  42.             blvdev=/dev/${blvdev##*/}
  43.             shift;;
  44.         -p)    proto=$2    # Boot proto file
  45.             [[ "$proto" != /* ]] && proto=`pwd`/$proto
  46.             shift;;
  47.         -q)    doquery=y;;    # Query size
  48.         -v)    doverify=y
  49.             [ "$action" = y ] && {
  50.                 usage; exit 1
  51.             }
  52.             action=y;;
  53.         -T)    platform=$2
  54.             shift;;
  55.         *)    usage; exit 1
  56.     esac
  57.     shift    # next flag
  58. done
  59. shift    # skip --

getopts:
  1. #!/bin/bash
  2. while getopts "ad:" opt; do
  3.   case $opt in
  4.     a)
  5.      echo "a"
  6.      ;;
  7.     d)
  8.       date=$OPTARG #get the value
  9.       ;;
  10.     ?)
  11.       echo "Usage: $0 [-d date]"
  12.       exit 1
  13.       ;;
  14.   esac
  15. done
  16. echo $date
阅读(1359) | 评论(0) | 转发(0) |
0

上一篇:用noclobber避免覆盖文件

下一篇:#, ##, %, %%

给主人留下些什么吧!~~