-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,935
  • 24
  • 76
  • 127

2 Answers2

0

Changing to the directory seems to be a straightforward approach:

echo "$(cd "${directory}"; pwd)"
d3pd
  • 7,935
  • 24
  • 76
  • 127
0

What you want is :

readlink -f "$directory"

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

Blusky
  • 3,470
  • 1
  • 19
  • 35