qodeninja
qodeninja

Reputation: 11266

How do you expand variables in UNIX/BASH?

Nested variables have prevented me from trying to use BASH more extensively... consider the following:

export SYS_DIR='/home/${LOGNAME}/sys'
export APP_DIR='${SYS_DIR}/app'

I always end up with

> set
APP_DIR=/home/${LOGNAME}/sys/app

why? lol

and how do I get what I want =/

I'm not trying to resolve ${${var}}, but rather actual strings as shown above

Upvotes: 3

Views: 2212

Answers (1)

Stephen
Stephen

Reputation: 49156

Use double quotes

export APP_DIR="${SYS_DIR}/app"

Single quotes treat everything inside as literal, not evaluated.

Upvotes: 10

Related Questions