Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active December 29, 2021 05:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/5c717da2184e5efecd303b8bc4eadd51 to your computer and use it in GitHub Desktop.
Save YumaInaura/5c717da2184e5efecd303b8bc4eadd51 to your computer and use it in GitHub Desktop.
Shell — How to detect some command using GNU or BSD ? ( man sed | grep GNU )

Shell — How to detect command is GNU or BSD ? ( man sed | grep GNU )

I think grep man is easy way.

This way is maybe not perfect but maybe not wrong.

BSD

For examole Mac OS has BSD commands by default.

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

GNU

On Mac OS g*** commands are BSD's. ( brew installed c )

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

Other command examples

bash-4.4$ man sed | grep -e BSD -e GNU | head -n 1
SED(1)                    BSD General Commands Manual                   SED(1)
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                   CUT(1)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment