Nohsib Nohsib -4 years ago 166
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download