Finding about which OS is running via shell script

JD jd1008 at gmail.com
Fri Apr 26 20:04:15 UTC 2013


On 04/26/2013 01:46 PM, Kevin Wilson wrote:
> Hello,
> My aim is to right a script that will behave differently
> when running it on Fedora or running it on Ubuntu.
> Is there a way to know from Bash whether the OS is ubuntu or
> Fedora (besides parsing /etc/issue ) ?
>
> rgs,
> Kevin
>
A quick way is to run uname
It receives the following options:

}$ uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

   -a, --all                print all information, in the following order,
                              except omit -p and -i if unknown:
   -s, --kernel-name        print the kernel name
   -n, --nodename           print the network node hostname
   -r, --kernel-release     print the kernel release
   -v, --kernel-version     print the kernel version
   -m, --machine            print the machine hardware name
   -p, --processor          print the processor type or "unknown"
   -i, --hardware-platform  print the hardware platform or "unknown"
   -o, --operating-system   print the operating system
       --help     display this help and exit
       --version  output version information and exit

Examples:

$ uname -a
Linux cme.ddlinkdns.com 3.5.0-27-generic #46-Ubuntu SMP Mon Mar 25 
20:00:05 UTC 2013 i686 athlon i686 GNU/Linux
$ uname -s
Linux
$ uname -n
cme
$ uname -r
3.5.0-27-generic
$ uname -v
#46-Ubuntu SMP Mon Mar 25 20:00:05 UTC 2013
$ uname -m
i686
$ uname -p
athlon
$ uname -i
i686
$ uname -o
GNU/Linux






More information about the ubuntu-users mailing list