UNIX, get environment variable

Solution 1:

You can do:

printenv VARIABLE_NAME

Solution 2:

type the following command in terminal, it will display all the list of environment variables

printenv

now print the wanted variable like this:

echo $VARIABLENAME

Solution 3:

Using ${!VAR_NAME} should be what you are looking for

> FOO=BAR123
> VAR_NAME=FOO
> echo ${VAR_NAME}
FOO
> echo ${!VAR_NAME}
BAR123

Solution 4:

Do you mean something like this:

ENV() {
    printf 'echo $%s\n' $1 | sh
}

This works in plain old Bourne shell.