Writing bash scripts for changing Mac OS / OSX settings?
For scripting that interacts directly with macOS, you're much better off writing AppleScript over shell. AppleScript is Apple's proprietary scripting language that contains many ways to interact with the operating system. In addition, AppleScript was designed to be a very human readable language. 

Plenty of documentation and tutorials for AppleScript can be found through a quick google search. Here are some Apple webpages to get you started:

Introduction to AppleScript
AppleScript fundamentals 

To write AppleScripts, open up Script Editor, located in Applications > Utilities. 

An example script to toggle macOS Sierra's dark mode, would be:

tell application "System Events"
tell appearance preferences
    if dark mode is false then
        set dark mode to true
    else
        set dark mode to false
    end if
end tell
end tell