instead of that for loop you can use sed again, like this:
Code:
cmd=$(printf "%s" "$dots" | sed 's![.]/!../!g')
cd "$cmd"
Putting all together you will get something like this:
Code:
_walk() {
cmd=$(printf "%s/" "$1" | sed 's![^./]!!g;s!//*!/!g;s!\./!!g;s![.]!../!g')
cd "$cmd"
}
It is definitely faster, simpler and posix compliant.