-
sw_vers
は、macOS のバージョンを確認するコマンド
% sw_vers
ProductName: macOS
ProductVersion: 15.6.1
BuildVersion: 24G90
- 1行で出力する
% sw_vers | xargs | awk '{ print $2 " " $4 " (" $6 ")" }'
macOS 15.6.1 (24G90)
- aliasで定義する
(4フィールドにも対応しておく)
.zshrc
alias vers="sw_vers | xargs | awk '{ if(NF==6){ print \$2 \" \" \$4 \" (\" \$6 \")\" }else{ print \$2 \" \" \$4\$6 \" (\" \$8 \")\"} }'
% vers
macOS 15.6.1 (24G90)
4フィールドの場合
% vers
macOS 13.0(a) (22A100)
`man sw_vers`
SW_VERS(1) General Commands Manual SW_VERS(1)
NAME
sw_vers – print macOS system version information
SYNOPSIS
sw_vers
sw_vers --productName
sw_vers --productVersion
sw_vers --productVersionExtra
sw_vers --buildVersion
DESCRIPTION
sw_vers prints macOS version information for the currently running
operating system on the local machine.
When executed with no options sw_vers prints a short list of version
properties:
% sw_vers
ProductName: macOS
ProductVersion: 13.0
ProductVersionExtra: (a)
BuildVersion: 22A100
The ProductName property provides the name of the operating system
release (typically "macOS"). The ProductVersion property defines the
version of the operating system release (for example, "11.3" or "12.0").
The ProductVersionExtra property defines the Rapid Security Response
version, if one is installed on the operating system (for example, "(a)"
or "(b)"). The BuildVersion property provides the specific revision of
the operating system as generated by the macOS build system.
OPTIONS
The output of sw_vers can be refined by the following options. These
long-form options can also be passed in lowercase for convenience.
--productName Print only the value of the ProductName property.
--productVersion Print only the value of the ProductVersion
property.
--productVersionExtra Print only the value of the ProductVersionExtra
property.
--buildVersion Print only the value of the BuildVersion property.
EXAMPLES
% sw_vers --productName
macOS
% sw_vers --productVersion
13.0
% sw_vers --productVersionExtra
(a)
% sw_vers --buildVersion
22A100
COMPATIBILITY
Previous versions of sw_vers respected the SYSTEM_VERSION_COMPAT
environment variable to provide compatibility fallback versions for
scripts which did not support the macOS 11.0+ version transition. This is
no longer supported, versions returned by sw_vers will always reflect the
real system version.
sw_vers is backwards compatible with previous versions which expect
options passed with a single dash, as in:
-productName
FILES
/System/Library/CoreServices/SystemVersion.plist
macOS 15.6 October 27, 2022 macOS 15.6
- ついでに クリップボードにもコピーするように変更
.zshrc
alias vers="sw_vers | xargs | \
awk '{ if(NF==6){ print \$2 \" \" \$4 \" (\" \$6 \")\" }else{ print \$2 \" \" \$4\$6 \" (\" \$8 \")\"} }' | \
tee `tty` | pbcopy"
便利です