随着macOS 10.15Catalina的发布,默认shell将从bash切换到zsh。在查看一些脚本和文档时,我意识到需要对参数扩展进行更改。
在问题bash regex to match semantic version number之后,我需要更新我收集语义版本号的方法。
在zsh中,如何使用参数扩展拆分语义版本号?
发布于 2019-07-23 20:19:32
While using my previous answer as a template,我能够将我的代码转换成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+18G87Note that (by default) zsh arrays start at index 1 0
https://stackoverflow.com/questions/57164075
复制相似问题