r/commandline • u/Serpent7776 • Oct 21 '23
Recursive bash function to replace cd ../
This 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*/} ;}
4
Upvotes
View all comments
Show parent comment
1
u/Serpent7776 Oct 22 '23
Yeah, it's just a silly obfuscated entry.
My initial real solution was like the following, but then spiced it up to be recursive and immutable.