How can I eliminate redundant components in a path?
For example, I would like to transform
/foo/../foo/bar
to
/foo/bar
How can I eliminate redundant components in a path?
For example, I would like to transform
/foo/../foo/bar
to
/foo/bar
 
    
    Using gnu realpath:
p='/foo/../foo/bar'
realpath -m "$p"
Output:
/foo/bar
As per realpath --help:
-m, --canonicalize-missing   no components of the path need exist
You can also use more commonly available readlink (thanks to @pjh):
readlink -m "$p"
 
    
    You might pipe through something like: sed 's-/../foo/-/-g' to replace up/down reference in path names.
