Normalizing Path Names with Bash

442

The bash function presented here normalizes path names. By normalize I mean it removes unneeded /./ and ../dir sequences. For example, ../d1/./d2/../f1 normalized would be ../d1/f1.

The first version of the function uses bash regular expressions. The /./ sequences are removed first during variable expansion with substitution by the line:

local   path=${1///.///}

Article Source Linux Journal
September 3, 2009, 1:10 pm

 

Read More