j0h

bashMod_cd_test_script

j0h
Feb 7th, 2026
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.95 KB | None | 0 0
  1. #!/home/m/Downloads/bash-5.3/bash
  2.  
  3. # testing script for a mod to bash that allows for cd -N to
  4. # navigate to N directories up instead of typing ../../../ or ......
  5. # whatever, plus cd -N should be itterable in scripts
  6. # if that could possibly be useful.
  7.  
  8. # Create test directory structure
  9. og=$(pwd)
  10. mkdir -p ~/testdir/a/b/c/d/e/f/g/h/i/j
  11. cd ~/testdir/a/b/c/d/e/f/g/h/i/j
  12. pwd
  13.  
  14. echo "cd -2 (should go up 2 directories)"
  15. cd -2
  16. pwd  
  17. echo "# Should show .../g/h/i"
  18.  
  19.  
  20. echo "# Test cd -1 (should work like cd -)"
  21. cd /tmp
  22. pwd
  23.  
  24. cd /usr
  25. pwd
  26. cd -1
  27. echo "# Should go back to /tmp"
  28. pwd
  29.  
  30. echo "# Test cd -0 (no-op)"
  31. cd -0
  32. pwd  
  33. echo "# Should still be in /tmp"
  34.  
  35. echo "# Test larger numbers"
  36. cd ~/testdir/a/b/c/d/e/f/g/h/i/j
  37. cd -5
  38. pwd  
  39. echo "# Should show .../a/b/c/d"
  40.  
  41. echo "# Test the original cd - still works"
  42. cd /tmp
  43. cd /usr
  44. cd -  
  45.  
  46. echo "# Should go back to /tmp"
  47. pwd
  48. cd -  
  49. echo "# Should go back to /usr"
  50. pwd
  51. cd $og
  52. ls
  53.  
Advertisement
Add Comment
Please, Sign In to add comment