2

Here is a WSL bash session in which I attempt to access an Environment variable within a perl one liner:

$ ln='Hello World'
$ echo $ln
Hello World
$ perl -E 'say $ENV{q(ln)}'

$

Why does the perl expression $ENV{q(ln)} not contain the expected Environment variable ln ?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Wes
  • 423
  • 3
  • 12

1 Answers1

2

You need to export the environment variable.

$ ln='Hello World'
$ export ln

or

$ export ln='Hello World'

See section 3.2.3 in the Bash Beginners' Guide, and the top answer to this stackoverflow question

Jim Davis
  • 5,241
  • 1
  • 26
  • 22