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