如何获取shell脚本的可选参数
2012-07-28 16:58
435 查看
直接上例子:
cat option_sh #!/bin/bash echo $* # get the optional arguments while getopts f:t: value do case $value in f ) RHOST_INFO=$OPTARG # 从$OPTARG中获得参数值 ;; t ) TIMEOUT=$OPTARG ;; esac done echo $@ shift $(($OPTIND-1)) # 偏移至后面的参数 echo $* echo $1 if [ $TIMEOUT == "30" ] # 获得的参数为字符串 then echo here fi ngnlinux1 [** NONE **]/home/qius $ ngnlinux1 [** NONE **]/home/qius $ ./option_sh -t 30 -f ss other paras -t 30 -f ss other paras -t 30 -f ss other paras
other paras
other
here使用方法:example.sh -f file_name -t timeoutvalue other paras
相关文章推荐
- shell脚本中如何获取命令的参数(1)
- shell脚本中如何获取命令的参数(2) ----处理命令参数
- linux下shell脚本获取网卡参数
- linux中的for、while循环输出中赋值变量及shell中循环获取脚本参数
- shell脚本如何获取当前时间
- 如何给shell脚本挂参数
- 如何给shell脚本传入参数小结
- db2 - 如何在shell中获取存储过程OUT型参数的返回值(awk)
- 如何给shell脚本传参数
- shell脚本--获取程序进程相关性能参数
- 如何给shell脚本传入参数小结
- 如何在shell脚本文件中获取awk的值, 存于变量中?
- shell 脚本之获取命令输出字符串以及函数参数传递
- shell脚本读取文本文件调用其他脚本传递获取参数
- shell脚本如何获取当前时间
- 对于shell脚本参数获取时的一点小技巧
- 在Bash shell脚本编程中,如何正确无误获取到“脚本选项参数”和“脚本参数”呢? 推荐
- shell脚本自动化部署-如何向expect脚本里面传递参数
- 脚本获取输入参数shell之getopt
- shell 脚本之获取命令输出字符串以及函数参数传递