2

I am trying to use an environmental variable to point to a file, run it through a subroutine and associate it with a variable. I managed it with Windows but I cannot get the syntax working for Linux..

This is what I have:

 my $config = read_config("$ENV{APP_HOME}/config/APP-linux.cfg");

my script dies when reaching this line with the error:

    Use of uninitialized value $ENV{"APP_HOME"} in concatenation (.) or string at ./XXXXX.pl

APP_HOME is defined as an environment variable (confirmed using set). What am I doing wrong?

9
  • does echo $APP_HOME returns the correct value from your shell? Commented Jun 5, 2014 at 16:44
  • @HunterMcMillen it doesnt... it gives: Name "main::APP_HOME" used only once: possible typo at ./test.pl line 8. Can't call method "echo" on an undefined value at ./test.pl line 8. Commented Jun 5, 2014 at 16:47
  • 2
    Did you just set it or export it? export APP_HOME=MY_VALUE Commented Jun 5, 2014 at 17:11
  • 1
    What does this display: perl -e 'print "$ENV{APP_HOME}\n";' Commented Jun 5, 2014 at 17:24
  • 1
    Examine your full list of environment variables: perl -MData::Dumper -e 'print Dumper \%ENV' Commented Jun 5, 2014 at 18:23

2 Answers 2

1

In bash, = simply creates a shell variable. These are not automatically exported to the environment. You need to do that explicitly.

Set a shell variable:

 $ AA=hello

Set and export another one (in a single statement):

 $ export BB=there

Start a new process:

 $ bash

Voila! Only the exported variable is inherited by the new process:

 $ echo "[$AA] [$BB]"
 [] [there]

Note that set does not set a variable. set AA=hello does not do what the Windows shell does.

Sign up to request clarification or add additional context in comments.

Comments

0

Okay, the solution was of my own stupidity. I set the variable in .bashrc using:

APP_HOME=$HOME/APP/DATA/STORAGE; export FINE_DIR

The RAPID_DIR had no right to be there. Was a remainder of a copy/paste and poor oversight... Changes FINE_DIR to APP_HOME and all is good.

Thankyou for all the guidance!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.