0

Suppose I have a variable in my bash script:

conf="~/Downloads"

where Downloads is an existing directory under my home directory.

The following complains that directory does not exist:

realpath $conf

How do I expand a path stored in a variable?

Please note that, in the actual script of mine, conf contains input from user, who may or may not input tilde. Hence, writing conf=~"/Downloads" is not an option.

UPDATE: Unfortunately, the question has been marked as duplicate and I cannot reply. The solution is to transform the value by eval "conf=$conf".

AlwaysLearning
  • 5,895
  • 2
  • 16
  • 50

0 Answers0