#/bin/bash
#set -x
set -e usage()
{
cat <<EOF
Usage:
`basename $` [OPTIONS] <non-option arguments> Purpose:
  xxxxxxxxxxxx Description:
  None Parameters:   OPTIONS
    -i image -- images, registry: by default
    -p -- host port, by default   <non-option arguments> Author:
  anor@xxxx.com Revision:
  -- Anor Initial Versiona EOF
exit
} ############################################
#declare options string including optional
#argument names separated from withsapce.
#g_opt_name includs optional arg names
#g_opt_<g_opt_name>, just holds optional arg value
#for example,
# Given optional args, -i, -p,
# the option arg variables respectivly should be as,
# g_opt_i
# g_opt_p
############################################
declare -a g_opt_names=(i: p:) ############################################
#init_args()
#initialize arguments before set them with
#command line values
############################################
init_args()
{
g_opt_i="registry:2" # the registry image from hub.docker.com
g_opt_p=
} ############################################
#parse_non_option_args()
#parse non option arguments here
############################################
parse_non_option_args()
{
#//TODD add your code to parse non-option arguments here. return ;
} ############################################
#main()
#add business logics in this [main] function
############################################
main()
{
#//TODD add your bussiness code here return ;
} #*******************************************************
########################################################
### Common functions here
########################################################
#*******************************************************
parse_args()
{ #check if showing usage
if [ "$1" == "--help" ]; then usage; fi init_args parse_options "$@" parse_non_option_args "$@"
}
parse_options()
{
local opt_names="${g_opt_names[@]}" local opt_string="$(echo -e "$opt_names" | tr -d '[[:space:]]')" log "opt_string=$opt_string" if [ -n "$opt_names" ]; then
while getopts $opt_string opt
do
for i in "${g_opt_names[@]}"
do
local opt_name=${i::}
local opt_var_name=g_opt_$opt_name
case $opt in
$opt_name )
if [ -z "$OPTARG" ]
then
eval $opt_var_name=
else
eval $opt_var_name=\"$OPTARG\"
fi
log "$opt_var_name=${!opt_var_name}"
;;
h ) usage ;;
\?) usage ;;
esac
done
done
fi
} #Purpose:
# echo log message
#
#Parameters:
# @.... -- log messages
#
log()
{
echo "[`date +'%Y-%m-%d %H:%M:%S'` $0]" "${@:1}"
} _main()
{ #parse optional
parse_args "$@" #main routine
main "$@" #successful log
log "Done!"
} _main "$@"

Bash Template的更多相关文章

  1. Enabling Active Directory Authentication for VMWare Server running on Linux《转载》

    Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breid ...

  2. Ansible--Ansible之Playbook

    Ansible之Playbook Playbook介绍 playbook参考文档 Playbook与ad-hoc相比,是一种完全不同的运用ansible的方式,类似与saltstack的state状态 ...

  3. Bash:-:-定义空变量作为输出结合换行符\n和column输出

    RET="" declare -a HOST=() declare -a ALL_SVR=() declare -a FREESVR=() ;i<${#_ALL_AGENT_ ...

  4. 介绍linux下利用编译bash设置root账号共用的权限审计设置

    在日常运维工作中,公司不同人员(一般是运维人员)共用root账号登录linux服务器进行维护管理,在不健全的账户权限审计制度下,一旦出现问题,就很难找出源头,甚是麻烦!在此,介绍下利用编译bash使不 ...

  5. Bash重定向

    1. 基础知识 文件描述符(File Descriptor),是进程对其所打开文件的索引,形式上是个非负整数.类 Unix 系统中,常用的特殊文件描述符如下: 文件描述符 名称 常用缩写 默认值 0 ...

  6. windows 10开启bash on windows,配置sshd,部署hadoop

    1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...

  7. Bash编程(5) Shell方法

    shell的方法在相同的进程内执行,与调用它的脚本一致.对于方法来说,脚本中的所有变量均可见,且不需要执行export.方法中可以创建局部变量,且不影响正在调用的脚本. 1. 定义语法 (1) Kor ...

  8. Bash脚本编程总结

    bash脚本编程之用户交互: read [option]… [name …]  -p ‘PROMPT’  -t TIMEOUT bash -n /path/to/some_script  检测脚本中的 ...

  9. NPM, BOWER, GIT, AND BASH PROXY CONFIGURATIONS

    Sources: http://digitaldrummerj.me/proxy-configurations/ When you are using npm, bower, and git behi ...

随机推荐

  1. cgi fastcgi wsgi nginx python Dispatching TurboGears Python via FCGI

    https://www.nginx.com/resources/wiki/start/topics/examples/simplepythonfcgi/ 117 2018-06-28 19:56:42 ...

  2. java操作CMD命令

    import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; public class CM ...

  3. assert的作用是什么

    assert()宏是用于保证满足某个特定条件,用法是: assert(表达式); 如果表达式的值为假,整个程序将退出,并输出一条错误信息.如果表达式的值为真则继续执行后面的语句. 使用这个宏前需要包含 ...

  4. AnimatorCompatHelper clearInterpolator

    supportLib 26.0.0+以上AnimatorCompatHelper类被移除 所以clearInterpolator(view)找不到 替换方案: TimeInterpolator mDe ...

  5. Lightoj 1140(数位DP)

    求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就 ...

  6. P4324 [JSOI2016]扭动的回文串

    传送门 对\(A\).\(B\)串各跑一遍\(manacher\),求出第\(1\).\(2\)类扭动回文串的最大长度. 考虑第三类的扭动回文串\(S(i,j,k)\),一定可以表示为\(A(i,l) ...

  7. 洛谷 P1966 火柴排队

    题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列火柴的高度互不相同, 两列火柴之间的距离定义为:∑(ai​−bi​)2 其中ai​ 表示 ...

  8. [USACO 2012 Mar Gold] Large Banner

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=127 又是一道这种题目,遇到一次跪一次,这次终于硬着头皮看懂了题解,但是谢 ...

  9. 51nod 1126 求递推序列的第N项

    1126 求递推序列的第N项  基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 有一个序列是这样定义的:f(1) = 1, f(2) = 1, f( ...

  10. 题解报告:hdu 1062 Text Reverse

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...