oracledba.help
Scripts

BASH Scripting Conventions

<- Scripts

Overview

What follows is a scripting architecture that is geared toward natural ease of coding and updating. Basically Wu Wei.

Optimally you want all your scripts to:

  1. Be standardized.
  2. Use a simple variable naming convention.
  3. Easily enable a feature without introducing bloat.
    Example by adding (sourcing) a specific library function.

Review cron script changes if need be.

Variable Naming Conventions

 • Reserve UPPER case for OS environment vars.
   Never declare any and change value of existing only when appropriate.
 • Use CamelCase (MyVar) for standard global vars.
   Format:   <TypeChar><Class><Descripter>
   Examples: sDirLogs, sEmailSA, sEmailDev
 • Prefix\Suffix
   String:    sMyStr
   Numeric:   nMyNumber
   Parameter: pMyVar
   me         Special var set to local function or script name.
              local me="${FUNCNAME[0]}" 
  • Use double-quotes around all strings vars (except in case statements).

CamelCase is used in favor of snake_case (lower_case_names_with_underscores) as they are shorter.

Built-Ins

# ${VAR^}  # upper single
# ${VAR^^} # upper all
# ${VAR,}  # lower single
# ${VAR,,} # lower all
# ${VAR~}  # swap case single
# ${VAR~~} # swap case all

VAR=BAR
printf ${VAR,,} # bar

More here.