bash 如何通过 bashrc 检查操作系统是 Sun Os 还是 Unix 或 Solaris
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9124347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I check if the Operating System is Sun Os or Unix or Solaris from by bashrc
提问by Kumar Alok
I want to know, how can we check in the bashrc file, what operating system is it?
我想知道,我们如何检查bashrc文件,它是什么操作系统?
回答by Basile Starynkevitch
Use uname -a
in your .bashrc
file.
uname -a
在您的.bashrc
文件中使用。
回答by jlliagre
There is no portable way to know what Operating System is running.
没有可移植的方法来了解正在运行的操作系统。
Depending on the OS, uname -s
will tell you what kernelyou are running but not necessarily what OS.
根据操作系统,uname -s
会告诉您正在运行的内核,但不一定是什么操作系统。
Moreover, it cannot be SunOS orUnix orSolaris. Solaris is all of them: both a Unix compliant OS and an OS based on the SunOS kernel.
此外,它不能是 SunOS或Unix或Solaris。Solaris 就是所有这些:既是兼容 Unix 的操作系统,又是基于 SunOS 内核的操作系统。
One of these might give you a precise answer depending on the Unix or Linux implementation:
其中之一可能会根据 Unix 或 Linux 实现为您提供准确的答案:
cat /etc/release # SVR4, Solaris
cat /etc/redhat-release
cat /etc/*elease
cat /etc/lsb-release
oslevel -r # AIX
system_profiler -detailLevel -2 # Mac OS/X
回答by jlliagre
Try this:
尝试这个:
$cat /etc/os-release
NAME="Ubuntu"
VERSION="12.04.4 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"
VERSION_ID="12.04"