kisrael
asked on
detecting version of linux
We have a shell script that currently asks if the user is running Debian, Red Hat, or SUSE, and adapts a makefile accordingly. (I think Red Hat may be the oddman out.) We'd like to determine what distribution of Linux they're running.
A short and acceptable (and wonderful) answer might be a snippet of shell script (including the #! at the top) that should run on all those flavors of Linux, and do the follow pseudocode: (I think the existing script runs under ksh and bash? Does Linux not usually come with ksh?)
IF INSTALL=REDHAT
echo redhat
END IF
IF INSTALL=SUSE
echo suse
END IF
IF INSTALL=DEBIAN
echo debian
END IF
I'm not sure what the most reliable way of detecting dist is; though gcc -v seems to work. But then I'm not sure how to redirect it's stderr to stdout under ksh and/or bash, and my shell scripting is weak enough that I don't know the easiest way of checking the result of that grep, so any advice on that would be appreciated as well...
Thanks!
A short and acceptable (and wonderful) answer might be a snippet of shell script (including the #! at the top) that should run on all those flavors of Linux, and do the follow pseudocode: (I think the existing script runs under ksh and bash? Does Linux not usually come with ksh?)
IF INSTALL=REDHAT
echo redhat
END IF
IF INSTALL=SUSE
echo suse
END IF
IF INSTALL=DEBIAN
echo debian
END IF
I'm not sure what the most reliable way of detecting dist is; though gcc -v seems to work. But then I'm not sure how to redirect it's stderr to stdout under ksh and/or bash, and my shell scripting is weak enough that I don't know the easiest way of checking the result of that grep, so any advice on that would be appreciated as well...
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On RedHat you can do "cat /proc/version"; don't know 'bout the others
szaboc, that has nothing to do with distributions and should be the same for all distributions with a reasonably recent kernel.
As you know the proc filesystem is a virtual filesystem provided by Linux (Linux is really only the kernel) as a link to read/alter some parameters, either by humans or user space programs.
/b
As you know the proc filesystem is a virtual filesystem provided by Linux (Linux is really only the kernel) as a link to read/alter some parameters, either by humans or user space programs.
/b
/usr/bin/lsb_release -a
/etc/redhat-release
/etc/debian_version
/etc/slackware-version
But in concurrence with bummerlord, I certainly wouldn't rely on this.