Skip to main content
Post Closed as "Duplicate" by terdon bash
deleted 6 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

Given I have in a bash script

ev=USER

How can I get the environment variable value for $USER using ev?

Tried naively doing:

echo ${"$"$ev}

which results in bad substitution.

I'd expect to get back whatever the value of $USER is.

thanks

Given I have in a bash script

ev=USER

How can I get the environment variable value for $USER using ev?

Tried naively doing:

echo ${"$"$ev}

which results in bad substitution.

I'd expect to get back whatever the value of $USER is.

thanks

Given I have in a bash script

ev=USER

How can I get the environment variable value for $USER using ev?

Tried naively doing:

echo ${"$"$ev}

which results in bad substitution.

I'd expect to get back whatever the value of $USER is.

Tweeted twitter.com/StackUnix/status/1101497329973121024
Became Hot Network Question
edited tags
Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k
Source Link
PaulB
  • 163
  • 5

Indirectly access environment variable

Given I have in a bash script

ev=USER

How can I get the environment variable value for $USER using ev?

Tried naively doing:

echo ${"$"$ev}

which results in bad substitution.

I'd expect to get back whatever the value of $USER is.

thanks