shelling out? - uname

Nik Clayton nik at
Fri Dec 8 14:28:14 GMT 2006

Hi Russ,

Russ Hogge wrote:
> Is there a good method of returning uname within perl.  I need to test if
> my script is running on Linux or Solaris, and suspect that there is a
> module that would tell me this information is a sane manner.
> Clearly I could just type:
> chomp($platform = `/usr/bin/uname`);
> But this strikes me as poor.
> Any thoughts?

For the specific case you describe, then the special variable $^O should do it.

   % perl -e 'print "$^O\n"';

More generally, stuff that Perl finds when it was built is stuffed in to  So you could also do:

   % perl -MConfig -e 'print $Config{osname}, "\n";'

($Config{osname} and $^O being identical).  %Config has other keys though. 
For example:

   % perl -MConfig -e 'print $Config{osvers}, "\n"';

which might also be helpful.


More information about the mailing list