I wrote this small function in my .zshrc file to make moving back in the directory tree faster:
#: Move back x director(y/ies). function bak () { local x="" local limit="$1" local msg="Can't move back $limit directories" [ -z "$limit" ] && limit=1 for ((i=0;i<limit;i++)); do x="../$x" done if ! cd "$x"; then echo "$msg"; fi } It works just fine except for 2 caveats:
While the function runs and I can move back in the directory tree, if I ever try to move past the limit (root "/") the function doesn't print out the error message. So basically this part
if ! cd "$x"; then echo "$msg"; fijust doesn't do anything.
If I remove that part (the if statement to print error message), the function no longer works.
Can anyone help me get the error message part to work, please? Also if anyone can explain why removing the error message part breaks the function that would be great.
..entry in the root directory, pointing right back to the root directory (runls -lid / /. /.., and you'll see that all three have the same inode number, i.e. they're all the exact same thing). Also, when you removed theifstatement, did you remove thecdalong with it?