Looking for a way to run a command depending on OS version
You can get the OS version using sw_vers -productVersion.

$ sw_vers -productVersion
10.13.2


You can test on this in a shell script using

if [[ $(sw_vers -productVersion) == 10.13.2 ]]; then …


To test any 10.12 or 10.13 version, you can use parse the output such as with this

if [[ $(sw_vers -productVersion | sed "s/10\.\([0-9][0-9]\).*/\1/") == 13 ]]; then …