How to evaluate a given path in a bash shell

Is there a bash command that takes a file path as input and returns an absolute file path? More specifically, I need a command that takes a path such as:

/tmp/yaneeve/kit/linux/../../output/kit/SOURCES//usr//apps/myapp/lib

and returns the path:

/ tmp / yaneeve / output / kit / SOURCES / usr / apps / myapp / lib

Thanks!

+3
source share
2 answers

Try it (Linux)

readlink -f
+5
source

If the path exists, there is a more portable way (even on Linux):

canonicalPath=$(cd "$path"; pwd)
+10
source

Source: https://habr.com/ru/post/1709160/


All Articles