Nohsib Nohsib - 2 months ago 10
Linux Question

How to convert ".." in path names to absolute name in a bash script?

How to convert the

in the path names to absolute path names in a bash script. That is, if I have a path
, I want this to be changed to the path without dots in it, in this case

How can I do that?


What you're looking for is readlink:

absolute_path=$(readlink -m /home/nohsib/dvc/../bop)

Please note: You need to use GNU's readlink implementation which offers the "-m" option. BSD's readlink for example does not.