-1

Drawing on a broadly similar answer, I would like to indirectly expand path variable to create another path.

Example

# Files directory
long_path='/very/long/path/that/I/dont/want/to/type'
archive_path='${long_path}/Archive'

# Print paths
echo -e "Long path: ${long_path}.\nArchive path: '${!archive_path}'."

Results

As shown below only the ${long_path} is printed correctly.

Long path: /very/long/path/that/I/dont/want/to/type.
Archive path: ''.
Konrad
  • 17,740
  • 16
  • 106
  • 167
  • This is non-sense... what is `dta_fld`? why do you (think you) need indirect expansion? – gniourf_gniourf Oct 12 '17 at 12:43
  • 1
    Still non-sense: `${archive_path}` expands to `${long_path}/Archive` (verbatim), and `${!archive_path}` will expand to the expansion of the variable named `${long_path}/Archive`... but there's no such variable! did you understand indirect expansion? why do you need indirect expansion? – gniourf_gniourf Oct 12 '17 at 12:45

1 Answers1

2

The variables in bash do not expand on single quotes, you need to double-quote them.

archive_path="${dta_fld}/Archive"

And from seeing your example code, you don't seem to have a candidate that needs indirect expansion. In-direct expansion works on a case like below, where the variable you are trying to expand is pre-defined

foo='bar'
bar='zoo'
printf "%s\n" "${!foo}"
Inian
  • 80,270
  • 14
  • 142
  • 161