-   Linux - Newbie (
-   -   How to differentiate between ubuntu and redhat in unix script or c preprocessor? (

manuabhi 07-23-2012 05:48 AM

How to differentiate between ubuntu and redhat in unix script or c preprocessor?

I am a newbie to linux. I have a file to execute which is copied in different directory based on redhat or ubuntu. Is there any unix script method or c preprocessor by which I can differentiate between Redhat or Ubuntu ?

Is there any other method to differentiate between redhat and ubuntu?

syg00 07-23-2012 07:11 AM

Simply check for the existence of /etc/redhat-release.

schneidz 07-23-2012 11:00 AM


uname -a -m -p

bsat 07-24-2012 02:24 AM

you can look into the file /etc/issue

evo2 07-24-2012 02:29 AM


all lsb compliant distros will identify themselves with the lsb_release command. The -i and -s flags will probably give you what you want.

lsb_release -is

manuabhi 07-24-2012 04:55 AM

Hi All,

Thanks for reply. Is there any way I can do with c programming as I am trying to write a cross platform code as well.

pan64 07-24-2012 04:57 AM

why do you want to differentiate? usually the same code will run on both.

manuabhi 07-24-2012 05:24 AM

@pan64 As i asked in question that we are copying a file in different directory based on whether Redhat or Ubuntu, to execute the file i need to know which linux flavor my code is running.

pan64 07-24-2012 05:36 AM

you wrote there is a file to execute copied into a dir. So you want to execute either /use/this/path/app or /use/that/dir/app?
the most simple way is to check if that app exists, fopen(path) is sucessful or not. Any other check you want to implement will be much more complex and will not give you better result.
You can try to open /etc/issue or /etc/redhat-release and parse, execute uname or lsb_release and evaluate the answer from c as well.

All times are GMT -5. The time now is 10:10 AM.