シェルでコマンドがBSD版かGNU版かを見分けるお手軽な方法


man を grep する手があるんじゃないだろうか。

BSD

Macでのコマンド類はデフォルトで BSD版なので、その例。

man man sed | grep -e BSD -e GNU | head -n 1
SED(1)                    BSD General Commands Manual                   SED(1)

GNU

Macでは GNU版のコマンドを brew で入れられる。その例。

man man gsed | grep -e BSD -e GNU | head -n 1
              disable all GNU extensions.

他のコマンドで試した例

bash-4.4$ man sed | grep -e BSD -e GNU | head -n 1
SED(1)                    BSD General Commands Manual
bash-4.4$ man gsed | grep -e BSD -e GNU | head -n 1
              disable all GNU extensions.
bash-4.4$ man cut | grep -e BSD -e GNU | head -n 1
CUT(1)                    BSD General Commands Manual
bash-4.4$ man gcut | grep -e BSD -e GNU | head -n 1
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
bash-4.4$ man stat | grep -e BSD -e GNU | head -n 1
STAT(1)                   BSD General Commands Manual                  STAT(1)
bash-4.4$ man gstat | grep -e BSD -e GNU | head -n 1
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>

Versions

  • Mac OS X High sierra

Links