-1

Let's say I have a variable like this:

directory="/home/lrh/package1/util/../.."

How could I convert it to the following?:

"/home/lrh"

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

d3pd
  • 7,237
  • 22
  • 68
  • 120

2 Answers2

0

Changing to the directory seems to be a straightforward approach:

echo "$(cd "${directory}"; pwd)"
d3pd
  • 7,237
  • 22
  • 68
  • 120
0

What you want is :

readlink -f "$directory"

(readlink: print resolved symbolic links or canonical file names)

Blusky
  • 3,113
  • 1
  • 17
  • 35