您的位置:首页 > 运维架构 > Shell

shell命令getopts

2015-10-30 10:51 549 查看
#!/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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: