Recursive bash function to replace cd ../

in #bash7 months ago

This simple recursive bash function replaces cd ..

. 1 works like cd ..
. 2 works like cd ../../ and so on.
. works like . 1.

.() { , ${1:-1}; }; 
,() { local N=$(($1-1)) C=${1/#0*/cd} D=${1/#[1-9*]/../}; ${C/#[1-9]*/,} ${N/-1/} ${2}${D/#0*/} ;}