Within a script I have a variable which contains a relative path to a directory. Is there any way to get the absolute path of the contents of this variable?
Asked
Active
Viewed 110 times
1 Answers
0
# cd /var/lib/foo
# rpath=../../bar
# echo $(cd "$rpath" && pwd)
/bar
# pwd
/var/lib/foo

Sammitch
- 30,782
- 7
- 50
- 77
-
This works when the name is a directory; it doesn't when the name is a file (and a close reading of the question suggests file rather than directory). – Jonathan Leffler Oct 16 '14 at 18:04