导航

shell命令getopts

Posted on 2015-10-30 10:52  ggzone  阅读(114)  评论(0编辑  收藏  举报
#!/bin/bash

set -e


cmd="ls"

while getopts :a:t:sn opt; do
  case $opt in
     a) cmd=$cmd" -a $OPTARG";;
     t) cmd="$cmd -t $OPTARG";;
     s) cmd="$cmd -s";;
     n) cmd="$cmd -n --no-dns";;
     *) echo "Invalid param";;
  esac
  echo $OPTIND
done
echo $cmd



Dev-FandeiMac:tmp code-pc$ ./test.sh -a test1.sh  -t hhh -s -n  ttss

ls -a test1.sh -t hhh -s -n --no-dns