Bash Template
#/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的更多相关文章
- 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 ...
- Ansible--Ansible之Playbook
Ansible之Playbook Playbook介绍 playbook参考文档 Playbook与ad-hoc相比,是一种完全不同的运用ansible的方式,类似与saltstack的state状态 ...
- Bash:-:-定义空变量作为输出结合换行符\n和column输出
RET="" declare -a HOST=() declare -a ALL_SVR=() declare -a FREESVR=() ;i<${#_ALL_AGENT_ ...
- 介绍linux下利用编译bash设置root账号共用的权限审计设置
在日常运维工作中,公司不同人员(一般是运维人员)共用root账号登录linux服务器进行维护管理,在不健全的账户权限审计制度下,一旦出现问题,就很难找出源头,甚是麻烦!在此,介绍下利用编译bash使不 ...
- Bash重定向
1. 基础知识 文件描述符(File Descriptor),是进程对其所打开文件的索引,形式上是个非负整数.类 Unix 系统中,常用的特殊文件描述符如下: 文件描述符 名称 常用缩写 默认值 0 ...
- windows 10开启bash on windows,配置sshd,部署hadoop
1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...
- Bash编程(5) Shell方法
shell的方法在相同的进程内执行,与调用它的脚本一致.对于方法来说,脚本中的所有变量均可见,且不需要执行export.方法中可以创建局部变量,且不影响正在调用的脚本. 1. 定义语法 (1) Kor ...
- Bash脚本编程总结
bash脚本编程之用户交互: read [option]… [name …] -p ‘PROMPT’ -t TIMEOUT bash -n /path/to/some_script 检测脚本中的 ...
- NPM, BOWER, GIT, AND BASH PROXY CONFIGURATIONS
Sources: http://digitaldrummerj.me/proxy-configurations/ When you are using npm, bower, and git behi ...
随机推荐
- 暴走吧!Snapdragon SDK开发速成指南
(文/Aurora J) Qualcomm的Snapdragon处理器.它快如闪电.效率极高.擅长挑战多任务极限,而且拥有攻城狮们梦寐以求的无限潜能.它能确保您的手机集4G LTE.极速体验.长久续航 ...
- CRM 插件奇怪的报错
CRM插件,数据库方式注册.报错 找不到方法:“Void Microsoft.Xrm.Sdk.Entity..ctor(System.String, System.Guid)”. 这个错误让人摸不着头 ...
- 迭代器-iteration
class CoffrrIterator implements Iterator<Coffee> { int cunt = size; public boolean hasNext() { ...
- problem in Sourcetree
1.The date is commit date not the date of author 2.The log line is ordered by time, actually it sho ...
- bzoj3668 [Noi2014]起床困难综合症——贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3668 一开始想着倒序推回去看看这一位能不能达到来着,因为这样好中途退出(以为不这样会T): ...
- 《StackGAN: Text to Photo-realistic Image Synthesis with Stacked GAN》论文笔记
出处:arxiv 2016 尚未出版 Motivation 根据文字描述来合成相片级真实感的图片是一项极具挑战性的任务.现有的生成手段,往往只能合成大体的目标,而丢失了生动的细节信息.StackGAN ...
- asp.net Identity2 角色(Role)的使用(三)用户管理,用户控制器和视图
修改用户控制器AccountController,增加角色管理器. public class AccountController : Controller { public AccountContro ...
- win10系统安装loadrunner11提示“为了对电脑进行保护 已经阻止此应用”的解决方案
在执行loadrunner安装包中的setup.exe时会有如下提示: 解决方法:点击Win+R快捷键打开运行,输入“ gpedit.msc”按下回车键打开组策略编辑: 在左边选择[计算机配置]→[W ...
- bzoj 3709: [PA2014]Bohater【贪心】
先打能回血的,按消耗从小到大打: 然后按回血量降序打剩下的(把消耗和回血反着看就是上一种怪,打法一样): 中间体力小于0就输出无解 #include<iostream> #include& ...
- 洛谷P4303 [AHOI2006]基因匹配(树状数组)
传送门 我已经连这种傻逼题都不会了orz 正常的dp是$O(n^2)$的,枚举第一个数组的$j$,然后第二个数组的$k$,如果相等,则$dp[i]=dp[j]+1$,否则$dp[i]=dp[j]$ 然 ...