Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

reading env variable in cygwin using perl

by Anonymous Monk
on Mar 27, 2006 at 10:32 UTC ( #539411=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i m trying to read environment variable in perl using
$OSTY = $ENV{OSTYPE};

this will return os type as "linux" or "solaris". but when i try for cygwin it returns empty string. is the some other syntax or way of finding value of env variable in cygwin
  • Comment on reading env variable in cygwin using perl

Replies are listed 'Best First'.
Re: reading env variable in cygwin using perl
by Corion (Pope) on Mar 27, 2006 at 10:55 UTC

    Most likely, the OSTYPE environment variable is simply not set, and hence you get an undefined value for it. You can check that by using:

    my $OSTY; if (not exists $ENV{OSTYPE}) { warn "Couldn't determine OSTYPE"; $OSTY = "<unknown>"; } else { $OSTY = $ENV{OSTYPE} };

    More likely though, you might want to inspect the $^O variable, which returns you the type of operating system:

    print "Running under $^O";

    You could combine the two techniques, and fall back if $ENV{OSTYPE} is unavailable:

    my $OSTY; if (not exists $ENV{OSTYPE}) { warn "Couldn't determine OSTYPE from environment - using $^O"; $OSTY = $^O; } else { $OSTY = $ENV{OSTYPE} };
Re: reading env variable in cygwin using perl
by monkey_boy (Priest) on Mar 27, 2006 at 10:55 UTC
    better still ...
    use English; print $OSNAME , "\n";
Re: reading env variable in cygwin using perl
by blogical (Pilgrim) on Mar 27, 2006 at 16:58 UTC
    My Cygwin %ENV (@work) has `OS`, not `OSTYPE`. Try running
    perl -e 'print $ENV{OS}'
    , which gives me `Windows_NT`.

    "One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
    - Henry David Thoreau, Walden

      ... or did you mean `$^OS`, which may be different?

      "One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
      - Henry David Thoreau, Walden

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://539411]
Approved by martymart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2021-07-29 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?