How do I get the full path of a relative directory in Bash?


This question already has an answer here:

  • Converting relative path into absolute path? 6 answers

Let's say I have a variable like this:


How could I convert it to the following?:


In other words, how could I have Bash "evaluate" the directory variable and get the full path?

Changing to the directory seems to be a straightforward approach:

echo "$(cd "${directory}"; pwd)"