I know there is, for example, hostnamectl
command on linux and system_profiler SPSoftwareDataType
command on macOS to know the operating system version, but I'm looking for a command that works for both operating systems. Does it exist?
Asked
Active
Viewed 375 times
0

AlessioF
- 453
- 2
- 8
- 19
-
`uname -v` is probably the closest you can get. Its *output*, though, isn't particularly standardized. – chepner May 19 '19 at 12:46
-
1Possible duplicate of [How to detect the OS from a Bash script?](https://stackoverflow.com/q/394230/608639), [How to check if running in Cygwin, Mac or Linux?](https://stackoverflow.com/q/3466166/608639), [uname](https://en.wikipedia.org/wiki/Uname) on Wikipedia, etc. – jww May 20 '19 at 01:10
1 Answers
1
I use uname -s
with tr
inside Makefile
to determine the system and decide whether to use .so
od .dylib
.
On macOS
> uname -s | tr '[:upper:]' '[:lower:]'
darwin
On Linux
> uname -s | tr '[:upper:]' '[:lower:]'
linux

Oo.oO
- 12,464
- 3
- 23
- 45