Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

How the script or executable uses environment variables will vary depending on the language you have used to write your script or executable. The following examples illustrate how environment variables are accessed in several common languages.

LanguageCommon methods of accessing environment variables
Perl

Use of the ENV array to access environment variables with Perl. For example:

#!/usr/bin/perl
my $user_email = $ENV{UPTIME_EMAIL};
my $user_mobile = $ENV{UPTIME_MOBILE};

PHP

When run from the command line, use the getenv() function to access environment variables within PHP. For example:

«?php
$user_email = getenv('UPTIME_EMAIL');
$user_mobile = getenv('UPTIME_MOBILE');

Bash and Ksh

Bash and Ksh enable you to access local environment variables just like any other local variable. For example:

#!/bin/bash
EMAIL=$UPTIME_EMAIL
MOBILE=$UPTIME_MOBILE

Batch File

Add the % symbol around the names of environment variables in Windows batch files. For example:

echo %UPTIME_EMAIL%
echo %UPTIME_MOBILE%

VB Script

Use the the oShell.Environment lookup function to access environment variables with VB Script. For example:

Dim email, mobile
Dim WshShell, objEnv

Set WshShell = CreateObject("WScript.Shell")

Set objEnv = WshShell.Environment("Process")

email = objEnv("UPTIME_EMAIL")
mobile = objEnv("UPTIME_MOBILE")