Advertisement
tolikpunkoff

get relative path example

Jun 2nd, 2019
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #get relative path example
  4. #start path: /tmp/test/dir1/subidr1/startpoint
  5. #end path: /tmp/test/dir2/subdir2/endpoint
  6.  
  7. START="/tmp/test/dir1/subidr1/startpoint"
  8. END="/tmp/test/dir2/subdir2/endpoint"
  9.  
  10. mkdir -p "$START"
  11. mkdir -p "$END"
  12.  
  13. cd "$START"
  14. echo -n "Start directory:"
  15. pwd
  16.  
  17. RP=`realpath --relative-to="$START" "$END"`
  18. echo "Relative path: $RP"
  19.  
  20. echo "CD to relative path:"
  21. cd "$RP"
  22.  
  23. echo -n "End directory:"
  24. pwd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement