Easy Bash
Easy Bash - a simple bash library to make scripting easier.

How to use it
Here is a step by step example to illustrate how easybash makes scripting easier.
Create your script
You can simply clone examples/template.sh.
git clone git@github.com:DBADaily/easybash.git
cd easybash
mkdir echo_dates
cp -a examples/template.sh echo_dates/echo_dates.sh
cd echo_dates/
vi echo_dates.sh
Step 1 - add your options as below
add_main_options() {
## custom options
# add your options here
add_options "s:" "start-date:" "START_DATE" "Y" "start date"
add_options "e:" "end-date:" "END_DATE" "Y" "end date"
...
}
Step 2 - write your custom function
# custom function
echo_dates() {
local lv_start_date="$1"
local lv_end_date="$2"
while [[ "${lv_start_date}" -le "${lv_end_date}" ]]; do
echo_blue_bold "Processing for date ${lv_start_date}"
log_trace "Work for date ${lv_start_date} done."
lv_start_date=$(date -d "${lv_start_date} + 1 days" +'%Y%m%d')
done
}
Step 3 - implement main function
main() {
add_main_options
parse_args "$@"
# add your logic here
if [[ "$CHECK_MODE" != "Y" ]]; then
echo_dates "${START_DATE}" "${END_DATE}"
elif [[ "$CHECK_MODE" == "Y" ]]; then
log_warning "CHECK MODE. Ski

Easy Bash是一个简单的bash库,旨在使脚本编写更方便。通过几步操作即可创建和运行脚本,包括添加选项、编写自定义函数和实现主函数。此外,脚本支持帮助消息显示、参数运行、详细模式、检查模式、配置文件生成等功能。
最低0.47元/天 解锁文章
439

被折叠的 条评论
为什么被折叠?



