1

With the release of macOS 10.15 Catalina, the default shell will be switched from bash to zsh. While reviewing some scripts and documentation, I realized that parameter expansion changes would need to be made.

Following the question bash regex to match semantic version number, I needed to update my method of collecting semantic version numbers.

In zsh, how can I split semantic version numbers using parameter expansion?

n8felton
  • 322
  • 2
  • 16

1 Answers1

1

While using my previous answer as a template, I was able to convert my code to use zsh parameter expansion.

product_version=$(sw_vers -productVersion) # 10.14.6
os_vers=( ${(@s:.:)product_version} ) # ( 10 14 6 )
os_vers_major="${os_vers[1]}" # 10
os_vers_minor="${os_vers[2]}" # 14
os_vers_patch="${os_vers[3]}" # 6
os_vers_build=$(sw_vers -buildVersion) #18G87
echo "${os_vers_major}.${os_vers_minor}.${os_vers_patch}+${os_vers_build}" # 10.14.6+18G87

Note that (by default) zsh arrays start at index 1 not 0

n8felton
  • 322
  • 2
  • 16